第一种:
通过web.xml配置加载spring上下文环境,其配置方式如下:
web.xml
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext*.xml</param-value>
- </context-param>
(在web.xml文件里面添加以上代码。只要将以applicationContext-开头的xml文件放到WEB-INF目录之下就可以了。一般会有applicationContext-service.xml和applicationContext-dao.xml。)
通过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,/WEB-INF/action-servlet.xml,,,,,可以多个"/>
- </plug-in>