explain:
(1) Why write this blog?: In[ RESTful development style 2: first experience of RESTful development style 2: develop the first RESTful project; ]Encountered the [exception thrown by Servlet.init() of Servlet[springmvc]] problem in; This blog records;
(2) Brief description of error cause: [Spring] While initializing the DispatcherServlet of MVC, it also loads applicationContext.xml to initialize the IoC container] → [therefore, if the IoC container cannot be initialized normally, the DispatcherServlet cannot be initialized normally] → [therefore, the reason for the exception is likely to be a problem in the applicationContext.xml file];
catalogue
1: Display of abnormal conditions;
2: Abnormal analysis and elimination;
1: Display of abnormal conditions;
After starting the Tomcat server, an error message is reported: the error message is too long, and some are copied here;
11-Nov-2021 01:34:59.121 information [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR Scanned for TLD But not yet included TLD. Enable debug logging for this logger to get scanned but not found in it TLD Integrity of JAR List. Skip unneeded during scan JAR Can reduce startup time and JSP Compile time. 11-Nov-2021 01:34:59.387 information [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.servlet.FrameworkServlet.initServletBean Initializing Servlet 'springmvc' .............................. .............................. .............................. 11-Nov-2021 01:35:07.857 information [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory hold web Application deployment to directory [D:\apache-tomcat-8.5.64\webapps\manager] 11-Nov-2021 01:35:07.938 information [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR Scanned for TLD But not yet included TLD. Enable debug logging for this logger to get scanned but not found in it TLD Integrity of JAR List. Skip unneeded during scan JAR Can reduce startup time and JSP Compile time. 11-Nov-2021 01:35:07.953 information [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web Application directory[D:\apache-tomcat-8.5.64\webapps\manager]Your deployment is already in progress[96]Completed in milliseconds
Then, the error message when accessing the browser: the error message reported by the browser is actually the same as that reported by the Tomcat server:
The error message in the first line is: [there is a bean with name=conversionService, but there is no];
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#0': Cannot create inner bean '(inner bean)#7cdfbb93' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7cdfbb93': Cannot resolve reference to bean 'conversionService' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'conversionService' available
2: Abnormal analysis and elimination;
Find the cause of the error:
Through the error message, you can see that it is Spring The dispatcher servlet of MVC cannot be initialized;
............................................................
However, it can be found that when initializing the dispatcher servlet, we need to load applicationContext.xml (initializing the IoC container);
Then, it is natural to think that the reason why DispatcherServlet cannot be initialized is because there is a problem when initializing the IoC container? Naturally, you will wonder whether there are bean s that cannot be initialized in applicationContext.xml or where the applicationContext.xml file is configured incorrectly;
............................................................
Take another look at the error message: through the error message, it is also found that [there is a bean with name=conversionService, but there is no];
............................................................
Looking at the contents of applicationContext.xml, I found a bean "conversionService" that could not be initialized;
That is, the reason for the error is: the old code is copied, but the old code is not handled cleanly: the bean entity of "conversionService" is not copied, but "conversionService" is copied. Therefore, the IoC container failed to initialize, resulting in the DispatcherServlet unable to initialize normally.