Struts+Spring整合

最近搞到了Struts,也小小的整合了一下,在这里顺手把他摘抄出来,做个记号,哈哈

[list=1]
  • 使用Spring的ActionSupport
  • 这个就不多说了,使用父类的getWebApplicationContext()就可以直接取到Spring的Context,然后继续使用ctx.getBean...即可
  • 使用DelegatingActionProxy
  • 这种方法是同时编写Action配置和Bean配置,然后通过name做为沟通的桥梁:
    <action-mappings>
    	<action path="/login" type="org.springframework.web.struts.DelegatingActionProxy"/>
    </action-mappings>
    

    <!--要注意的是,由于id不能写"/"所以这里用name-->
    <beans>
    	<bean name="/login" class="com.gxaccp.epet.web.struts.action.LoginAction"/>
    </beans>
    
  • 使用DelegatingRequestProcessor
  • 由于上面不能在action里直接定义type...难免有点不爽~,于是乎可以使用
     <controller processorClass="org.springframework.web.struts.
       DelegatingRequestProcessor"/>
    

    然后Struts就可以了,虽然那个type配了也没用...但是至少可以满足一下视觉效果
    <action-mappings>
    	<action path="/login" type="xxxx.LoginAction"/>
    </action-mappings>
    
  • 使用AutowiringRequestProcessor
  • 使用AutowiringRequestProcessor是比上述的方法更加集约化的一种做法,在Spring中还提供这个可以auto-wire的Processor,默认的装配方式是by-name,这样就不用在Spring中配置对应的Action了,届时Spring会进行自动装配,当然,by-name的优缺点大家都知道了,就仁者见仁,智者见智了
    <action-mappings>
    	<action path="/login" type="xxxx.LoginAction"/>
    </action-mappings>
    
    <!-- 对ActionServlet进行配置 -->
    <controller processorClass="org.springframework.web.struts.AutowiringRequestProcessor"/>
    

    [/list]

    关于ContextLoaderPlugin和ContextLoaderListener
    不知道这个设计上的问题大家还遇到不,可以参看robbin的帖子: http://www.iteye.com/topic/15057,总体上遵循一点,Spring的配置文件按照模块和层次进行拆分,各司其职,就不会出现OpenSessionInView失效的问题

    你可能感兴趣的:(spring,xml,bean,struts)