整合 Struts 和 Spring

整合 Struts Spring三种方式:<o:p></o:p>

1:使用 SpringActionSupport 整合 Structs2: Spring DelegatingRequestProcessor 覆盖 Struts RequestProcessor3: Struts Action 管理委托 Spring 框架 <o:p></o:p>

您使用哪都需要使用 Spring ContextLoaderPlugin Struts ActionServlet Spring 用程序境。就像添加任何其他插件一简单地向您的 struts-config.xml 文件添加插件通过加载吧spring的配置文件加载进来:如下所示<o:p></o:p>

<plug-in className=<o:p></o:p>

  "org.springframework.web.struts.ContextLoaderPlugIn"><o:p></o:p>

    <set-property property="contextConfigLocation" value="/WEB-INF/beans.xml"/><o:p></o:p>

 </plug-in><o:p></o:p>

窍门 1. 使用 Spring ActionSupport(strutsspring耦合在一起了)<o:p></o:p>

org.springframework.web.struts.ActionSupport类提供了一个 getWebApplicationContext() 方法。您所做的只是从 Spring ActionSupport 而不是 Struts Action 类扩展您的public class SearchSubmit extends ActionSupport {  //下面execute方法里的内容,strutsspring耦合在一起了<o:p></o:p>

ApplicationContext ctx = getWebApplicationContext();  <o:p></o:p>
    BookService bookService =  (BookService) ctx.getBean("bookService");<o:p></o:p>
}//不继承ActionSupport;这里换成直接自己通过各种各种ApplicationContext来读取springbean定义//文件(这种情况不需要上面的< plug-in>标签也可以)<o:p></o:p>

窍门 2. 覆盖 RequestProcessor<o:p></o:p>

 来覆盖 Struts   理程序<controller processorClass="org.springframework.web.struts. DelegatingRequestProcessor"/>是在我的 Spring 该动
<beans><o:p></o:p>
  <bean id="bookService" class="ca.nexcel.books.business.BookServiceImpl"/><o:p></o:p>
  <bean name="/searchSubmit" class="ca.nexcel.books.actions.SearchSubmit"> |(1)<o:p></o:p>
     <property name="bookService"><o:p></o:p>
        <ref bean="bookService"/><o:p></o:p>
     </property><o:p></o:p>
  </bean><o:p></o:p>
</beans><o:p></o:p>
 (1) ,我使用名称属性注册了一个 bean struts-config 作映射名称。 示了一个 JavaBean  Spring 填充属性SearchSubmit类就是Action里面定义了 private BookService bookServiceget/set方法.<o:p></o:p>
缺点:  tilesprocessor需要手整合 Spring  

窍门 3. 作管理委托 Spring<o:p></o:p>

 Strut 作管理委托 Spring  作映射中注册一个代理来实现。代理负责 Spring 境中 Struts 作。由于作在 Spring 作的 JavaBean 为应 Spring  AOP 截器之的特性来了可能。Action类和上面那种情况的类一样<o:p></o:p>
<action    path="/searchSubmit" <o:p></o:p>
             type="org.springframework.web.struts.DelegatingActionProxy" |(1)<o:p></o:p>
             input="/searchEntry.do"<o:p></o:p>
             validate="true"<o:p></o:p>
             name="searchForm"><o:p></o:p>
             <forward name="success" path="/WEB-INF/pages/detail.jsp"/><o:p></o:p>
             <forward name="failure" path="/WEB-INF/pages/search.jsp"/><o:p></o:p>
    </action>  <o:p></o:p>
 struts-config.xml 。它注册 Spring 的名称,而不是声明作的名,如(1所示。DelegatingActionProxy 使用作映射名称 Spring 境中的作。就是我使用  
<beans><o:p></o:p>
  <bean id="bookService" class="ca.nexcel.books.business.BookServiceImpl"/><o:p></o:p>
  <bean name="/searchSubmit"   class="ca.nexcel.books.actions.SearchSubmit"><o:p></o:p>
     <property name="bookService"><o:p></o:p>
        <ref bean="bookService"/><o:p></o:p>
     </property><o:p></o:p>
  </bean> <o:p></o:p>
*Spring Bean NameStruts Action Path关联,当Struts载对应ActionDelegatingActionProxy入的pathSpring Context对应bean例返回Struts

作委托的点不止如此。一旦 Spring 控制您的 Struts

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值