spring 与struts 整合

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>
          
这样就配置完成





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值