1.spring与struts 的整合的主要目的是 让spring ioc 容器来来管理 action ,interceptor,result 的创建和依赖关系
2.spring struts整合 struts 自带了一个插件 struts-spring-plugin 当我们引入此插件的时候 其实spring 和struts2
还没有真正的整合 因为 struts 是web 项目 tomact 还无法加载 spring xml 配置文档 此时打开tomact 时报错的
3.最好去查一下spring 或者struts 的配置文档http://struts.apache.org/docs/spring-plugin.html
4.整合的具体步骤
第一导入struts插件 struts-spring-plugin
第二部 在web.xml 配置2项
<listener> //用来配置web 服务器可以加载 配置文件
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param> //告诉我们的配置文件放在哪个位置
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value><!-- 也可以加载很多的文件用逗号分开 -->
</context-param>
第三部 在struts 配置文件中
步入<constant name="struts.objectFactory" value="spring"></constant> 此配置是struts 的对象由spring创建
<constant name="struts.objectFactory.spring.autoWire" value="name"> 装配类型是按照name 如不配置的话是按照type
最重要的一点是 action 的class 就要去找 spring xml 的bean 了
struts.xml
<action name="hello" class="helloaction" >
<result name="success">/index.jsp</result>
spring.xml
<bean id="helloaction" class="com.ss.action.helloaction" scope="prototype">
<property name="mdao" ref="Mangerdaoimpl"></property>
</bean>
这样就配置完成
2.spring struts整合 struts 自带了一个插件 struts-spring-plugin 当我们引入此插件的时候 其实spring 和struts2
还没有真正的整合 因为 struts 是web 项目 tomact 还无法加载 spring xml 配置文档 此时打开tomact 时报错的
3.最好去查一下spring 或者struts 的配置文档http://struts.apache.org/docs/spring-plugin.html
4.整合的具体步骤
第一导入struts插件 struts-spring-plugin
第二部 在web.xml 配置2项
<listener> //用来配置web 服务器可以加载 配置文件
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param> //告诉我们的配置文件放在哪个位置
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value><!-- 也可以加载很多的文件用逗号分开 -->
</context-param>
第三部 在struts 配置文件中
步入<constant name="struts.objectFactory" value="spring"></constant> 此配置是struts 的对象由spring创建
<constant name="struts.objectFactory.spring.autoWire" value="name"> 装配类型是按照name 如不配置的话是按照type
最重要的一点是 action 的class 就要去找 spring xml 的bean 了
struts.xml
<action name="hello" class="helloaction" >
<result name="success">/index.jsp</result>
spring.xml
<bean id="helloaction" class="com.ss.action.helloaction" scope="prototype">
<property name="mdao" ref="Mangerdaoimpl"></property>
</bean>
这样就配置完成