首先說一下struts1加載spring的兩種方式:
第一種:通過web.xml配置加載spring上下文環境,其配置方式如下:
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
通過listener加載
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
或者利用severlet類加載
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
第二種方式:
使用Struts插件
在struts-config.xml中
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
這兩種配置的明顯區別就是,第一種方式可以配置多個spring配置文件。而且第一種方式應該說是web容器加載spring的方式