Spring / Spring MVC Interview questions
Can we have multiple Spring configuration files in Spring MVC?
Yes, we can have more than one spring context files. The following are the 2 ways to configure multiple context files.
1. Specify the list of files in web.xml file using contextConfigLocation init parameter.
<servlet-name>springMVC</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> WEB-INF/spring-core-context.xml, WEB-INF/spring-DAO.xml, WEB-INF/spring-Services.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
2. Import the configuration files into a existing configuration file that is already configured.
<beans> <import resource="spring-core-context.xml"/> <import resource="spring-DAO.xml"/> <import resource="spring-services.xml"/> ... //other configurations </beans>
More Related questions...