Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xml。
当需要载入多个spring相关的配置文件时,首先加载ContextLoaderListener类,再指定context-param中指定多个spring配置文件,使用逗号分别隔开各个文件。为了使用方便可以将配置文件进行MVC式的分解,配置控制器Bean的配置文件放置在一个xml文件中,server的Bean放在service.xml文件中。
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/controllers.xml,/WEB-INF/service.xml</param-value>
[color=red]//<param-value>importMultiple.xml</param-value> [/color]
</context-param>
<servlet>
<servlet-name>dispatch</servlet>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<servlet-pattern>*.*</servlet-pattern>
</servlet-mapping>
[color=darkblue]importMultiple.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="classpath:vincent/vincent-spring-security.xml"/>
<import resource="classpath:vincent/vincent-spring-wrappers.xml"/>
<import resource="classpath:vincent/vincent-spring-services.xml"/>
<import resource="classpath:cvincent/cvincent-spring-services.xml"/>
<import resource="classpath:cvincent/cvincent-web-spring.xml"/>
<import resource="classpath:cvincent/cvincent-spring-security.xml"/>
</beans>[/color]
当需要载入多个spring相关的配置文件时,首先加载ContextLoaderListener类,再指定context-param中指定多个spring配置文件,使用逗号分别隔开各个文件。为了使用方便可以将配置文件进行MVC式的分解,配置控制器Bean的配置文件放置在一个xml文件中,server的Bean放在service.xml文件中。
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/controllers.xml,/WEB-INF/service.xml</param-value>
[color=red]//<param-value>importMultiple.xml</param-value> [/color]
</context-param>
<servlet>
<servlet-name>dispatch</servlet>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<servlet-pattern>*.*</servlet-pattern>
</servlet-mapping>
[color=darkblue]importMultiple.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="classpath:vincent/vincent-spring-security.xml"/>
<import resource="classpath:vincent/vincent-spring-wrappers.xml"/>
<import resource="classpath:vincent/vincent-spring-services.xml"/>
<import resource="classpath:cvincent/cvincent-spring-services.xml"/>
<import resource="classpath:cvincent/cvincent-web-spring.xml"/>
<import resource="classpath:cvincent/cvincent-spring-security.xml"/>
</beans>[/color]