由于自己在公司做struts2+spring+mybatis开发,里面对配置文件的管理特别好,自己开发的模块自己写配置文件,所以今天晚上就对ssh框架的多文件配置做了一下实践。
web.xml文件如下:
<context-param>
<param-name>contextConfigLocation</param-name> --必须为这个,这是spring容器查找的依据
<param-value>classpath:applicationContext.xml,/WEB-INF/customization/*.xml</param-value> --多个spring配置文件以,分隔
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener --spring加载配置文件的类
</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>config</param-name> --多个struts2配置文件的标记,必须为这个
<param-value>
struts-default.xml,struts-plugin.xml, --上面这两个必须加上,否则会报No mapping found for dependency[type=com.opensymphony.xwork2.ObjectFactory, name='default']
/WEB-INF/customization/*.xml --自己定义的多个strut2配置文件
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
当然spring还可以在applicationContext.xml中通过<import resource>来引入
在strut2中可以通过<include file='''>来引入