您的位置:首页 > 编程语言 > Java开发

Struts1.x加载Spring的两种方式

2008-10-27 20:13 281 查看
通过web.xml配置加载spring上下文环境,其配置方式如下:

 

第一种:
web.xml
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

(在web.xml文件里面添加以上代码。只要将以applicationContext-开头的xml文件放到src目录之下就可以了。

一般有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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: