struts2加载多个配置文件:
1、在struts.xml中用include加入,例如
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"></constant><!-- 把action交给spring -->
<constant name="struts.devMode" value="true"></constant><!-- 设置为开发模式 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<include file="struts_teacher.xml"></include>
<include file="struts_student.xml"></include><include file="struts_admin.xml"></include>
</struts>
2、在web.xml中配置:
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,/WEB-INF/struts.xml</param-value>
</init-param>
spring加载多个配置文件:
1、在ApplicationContext.xml中用import加入,例如
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<import resource="applicationContext_admin.xml" />
<import resource="applicationContext_classes.xml" />
<import resource="applicationContext_course.xml" />
<import resource="applicationContext_evaluation.xml" />
<import resource="applicationContext_feedback.xml" />
<import resource="applicationContext_post.xml" />
</beans>
2、在web.xml中配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext_*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>encoding</filter-name>
<filter-class>com.isoftstone.trms.util.CharFilter</filter-class>
</filter><filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></ web-app>