Downloading both mvc-dispatcher-servlet.xml and applicationContext.xml?

I am using Spring 3 MVC. I have both mvc-dispatcher-servlet.xml and applicationContext.xml. But applicationContext.xml is not loading, only loading mvc-dispatcher-servlet.xml.

Any problem with my configuration?

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/mvc-dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/extendedContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> 
+2
source share
2 answers

The simplest configuration is to use the import tag in the XML servlet dispatcher:

 <import resource="classpath:spring/applicationContext.xml" /> 

This is described in section 3.2.2.1:

http://docs.spring.io/spring/docs/2.0.8/reference/beans.html

Here is another question / answer to this question:

ContextLoaderListener or not?

+1
source

One option is to download all context files using a ContextLoader, separated by commas .

  <web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/mvc-dispatcher-servlet.xml, classpath:spring/applicationContext.xml, classpath:spring/extendedContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> 
+1
source

All Articles