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>
第一种:
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>
相关文章推荐
- Spring加载配置文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- J2EE 加载Spring的applicationContext.xml文件的两种方式
- 使用web.xml方式加载Spring时,获取Spring context的两种方式
- 使用web.xml方式加载Spring时,获取Spring context的两种方式
- Spring加载properties文件的两种方式
- Spring加载properties文件的两种方式
- 使用web.xml方式加载Spring时,获取Spring context的两种方式
- Spring加载properties文件的两种方式实例详解
- Spring加载properties文件的两种方式
- spring加载配置文件的两种方式
- Spring加载properties文件的两种方式