Recently, I encountered various strange exceptions when I used idea to build an aggregation project. Here is an exception reported by the operation of its sub module:
The prompt of exception information is:
Error creating bean with name ‘mvcContentNegotiationManager’: Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.web.accept.ContentNegotiationManagerFactoryBean] from ClassLoader [sun.misc.Launcher$ [email protected] ]
Check whether the POM file of the sub module depends on the parent class. Of course, many people will find that when wearing the submodule, the POM file of the sub module will automatically depend on the parent class (as shown in the figure below)
If the dependency in the above figure is not automatically generated after inspection, and you have the same exception as me, then the parent project dependency is added to solve the exception with a high probability
After consulting relevant posts on the Internet and repeated experiments for many times, I found that:
This bug is because we created a module with the same name before, and then we removed it. Then we automatically generate webapp module through the skeleton, so that the module generated by the skeleton will completely overwrite your original POM file!!!
Unfortunately, you need the parent project dependency to start the project, then you will have this bug!
The safest and most reliable solution to avoid problem reproduction: check the dependency of POM file every time you create a sub module. If not, solve it manually
Of course, there are various online solutions, but I have tried and found that it can temporarily solve the problem, but it will still be overwritten the next time I use the skeleton to generate a module with the same name
Solution 2 (slightly reliable):
Setting — build — Maven — ignored files, cancel the ignored POM file, and the parent project dependency will be automatically added!
The root cause is that we have created modules with the same name before, but they are not really removed There is still a lot of information about deleting modules in the idea, so when creating a new module, the idea will automatically ignore the new module with the same name we wrote
Of course, a large part of the impact is because we use automatic skeleton generation!