Home > Back-end >  Request: for SpringMVC DispatcherServlet/XML/WEB - INF/applicationContext.
Request: for SpringMVC DispatcherServlet/XML/WEB - INF/applicationContext.

Time:09-27

Set up for springmvc web project, only one controller layer, so the project web. The XML file, only configuration DispatcherServlet,
Web.xml contents:
& lt; ! - for springMvc containers - & gt;
& lt; Servlet>
& lt; The servlet - name> SpringMvc
& lt; The servlet - class> Org. Springframework. Web. Servlet. DispatcherServlet
& lt; Init - param>
& lt; Param - name> ContextConfigLocation
& lt; Param - value> The classpath: spring/spring - the MVC. Xml
& lt;/init - param>
& lt; The load - on - startup> 1
& lt;/servlet>
& lt; The servlet - mapping>
& lt; The servlet - name> SpringMvc
& lt; Url - pattern> *. Do
& lt;/servlet - mapping>
But at the time of startup project, tip: Java. IO. FileNotFoundException: Could not open the ServletContext resource [/WEB - INF/applicationContext. XML]

While it is possible to solve the problem by means of the following,
& lt; The context - param>
& lt; Param - name> ContextConfigLocation
& lt; Param - value> The classpath: spring/spring - the MVC. Xml
& lt;/context - param>

But will result in the spring - the MVC. XML loaded twice, not think, a great god grant instruction,

Ps: also set up purely for springmvc project before, did not appear this problem, is spring version 5.2.2. RELEASE,

The error log:
[the DEBUG] localhost - startStop - 1 org. Springframework. Context. Support. AbstractApplicationContext. PrepareRefresh (AbstractApplicationContext. Java: 595) the 2020-04-12 21:37:21, 908 ms: 53 Refreshing Root WebApplicationContext
[ERROR] localhost - startStop - 1 org. Springframework. Web. Context. ContextLoader. InitWebApplicationContext (ContextLoader. Java: 313) the 21:37:21 2020-04-12, 939, 84 ms: context initialization failed
Org. Springframework. Beans. Factory. BeanDefinitionStoreException: IOException parsing XML document from the ServletContext resource [/WEB - INF/applicationContext. XML]; Nested exception is Java. IO. FileNotFoundException: Could not open the ServletContext resource/XML/WEB - INF/applicationContext.
The at org. Springframework. Beans. Factory. XML. XmlBeanDefinitionReader. LoadBeanDefinitions (XmlBeanDefinitionReader. Java: 345)
The at org. Springframework. Beans. Factory. XML. XmlBeanDefinitionReader. LoadBeanDefinitions (XmlBeanDefinitionReader. Java: 305)
The at org. Springframework. Beans. Factory. Support. AbstractBeanDefinitionReader. LoadBeanDefinitions (AbstractBeanDefinitionReader. Java: 188)
The at org. Springframework. Beans. Factory. Support. AbstractBeanDefinitionReader. LoadBeanDefinitions (AbstractBeanDefinitionReader. Java: 224)
The at org. Springframework. Beans. Factory. Support. AbstractBeanDefinitionReader. LoadBeanDefinitions (AbstractBeanDefinitionReader. Java: 195)
At org. Springframework. Web. Context. Support the XmlWebApplicationContext. LoadBeanDefinitions (XmlWebApplicationContext. Java: 125)
At org. Springframework. Web. Context. Support the XmlWebApplicationContext. LoadBeanDefinitions (XmlWebApplicationContext. Java: 94)
The at org. Springframework. Context. Support. AbstractRefreshableApplicationContext. RefreshBeanFactory (AbstractRefreshableApplicationContext. Java: 133)
The at org. Springframework. Context. Support. AbstractApplicationContext. ObtainFreshBeanFactory (AbstractApplicationContext. Java: 637)
The at org. Springframework. Context. Support. AbstractApplicationContext. Refresh (AbstractApplicationContext. Java: 522)
The at org. Springframework. Web. Context. ContextLoader. ConfigureAndRefreshWebApplicationContext (ContextLoader. Java: 401)
The at org. Springframework. Web. Context. ContextLoader. InitWebApplicationContext (ContextLoader. Java: 292)
The at org. Springframework. Web. Context. ContextLoaderListener. ContextInitialized (ContextLoaderListener. Java: 103)
The at org. Apache. Catalina. Core. StandardContext. ListenerStart (StandardContext. Java: 4939)
The at org. Apache. Catalina. Core. StandardContext. StartInternal (StandardContext. Java: 5434)
The at org. Apache. Catalina. Util. LifecycleBase. Start (LifecycleBase. Java: 150)
The at org. Apache. Catalina. Core. ContainerBase $StartChild. Call (1559) ContainerBase. Java:
The at org. Apache. Catalina. Core. ContainerBase $StartChild. Call (1549) ContainerBase. Java:
The at Java. Util. Concurrent. FutureTask. Run (FutureTask. Java: 266)
The at Java. Util. Concurrent. ThreadPoolExecutor. RunWorker (ThreadPoolExecutor. Java: 1149)
The at Java. Util. Concurrent. ThreadPoolExecutor $Worker. The run (ThreadPoolExecutor. Java: 624)
The at Java. Lang. Thread. The run (Thread. Java: 748)
Under Caused by: Java. IO. FileNotFoundException: Could not open the ServletContext resource/XML/WEB - INF/applicationContext.
The at org. Springframework. Web. Context. Support. ServletContextResource. GetInputStream (ServletContextResource. Java: 159)
The at org. Springframework. Beans. Factory. XML. XmlBeanDefinitionReader. LoadBeanDefinitions (XmlBeanDefinitionReader. Java: 331)
. 21 more

Pom file content is as follows:
& lt; Dependencies>
& lt; ! - the log4j slf4j - & gt;
& lt; Dependency>
& lt; GroupId> Log4j & lt;/groupId>
& lt; ArtifactId> Log4j & lt;/artifactId>
& lt;/dependency>
& lt; Dependency>
& lt; GroupId> Org. Slf4j & lt;/groupId>
& lt; ArtifactId> Slf4j - api
& lt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related