struts与spring整合
有3种方法:
基本思路就是让struts交出生成action控制权,然后通过配置在spring中产生,记住一种就好了。。。。。。。个人偏好第一种,只需要修改1个配置文件,哈哈
1.通过struts-config.xml来使web容器加载spring
struts-config.xml中:
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
2.使用web.xml来使web容器加载spring
struts-config.xml中:
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
web.xml中:
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
3.使用web.xml来使web容器加载spring,这种方法前提支持servletAPI2.3
struts-config.xml中:
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
web.xml中:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
有3种方法:
基本思路就是让struts交出生成action控制权,然后通过配置在spring中产生,记住一种就好了。。。。。。。个人偏好第一种,只需要修改1个配置文件,哈哈
1.通过struts-config.xml来使web容器加载spring
struts-config.xml中:
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
2.使用web.xml来使web容器加载spring
struts-config.xml中:
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
web.xml中:
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
3.使用web.xml来使web容器加载spring,这种方法前提支持servletAPI2.3
struts-config.xml中:
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
web.xml中:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>