如何将旧的Struts应用程序与Spring 3.x集成 [英] How to integrate an old Struts application with Spring 3.x

查看:58
本文介绍了如何将旧的Struts应用程序与Spring 3.x集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何以及将Struts 1.x应用程序与Spring 3.x集成的首选方式是什么,以便我们可以从IOC的东西中受益.

i was wondering how to and what the prefered way of integrating an Struts 1.x application with Spring 3.x so we can benefit from the IOC stuff.

推荐答案

使用

Use ContextLoaderPlugin and set the struts controller to the processorClass "AutowiringRequestProcessor" like this (in struts-config.xml):

<controller>
    <set-property property="processorClass" value="org.springframework.web.struts.AutowiringRequestProcessor" />
</controller>

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/config/action-servlet.xml"/>
</plug-in>

action-servlet.xml必须是一个空的bean上下文文件:

action-servlet.xml has to be an empty beans context file:

<beans></beans>

在web.xml中的ActionServlet中添加以下初始化参数:

Add the following init parameter to the ActionServlet in web.xml:

<init-param>
    <param-name>autowire</param-name>
    <param-value>byName</param-value>
</init-param>

只需编写常规的struts动作,并在每个动作中添加注释"@Component",以便spring可以发现这些动作并从中创建一个bean. "AutowiringRequestProcessor"将找到与在struts-config.xml中定义的动作类匹配的正确的bean.

Just write regular struts actions, and add the annotation "@Component" to every action so that spring will discover the actions and creates a bean out of it. The "AutowiringRequestProcessor" will find the right bean that matches the action class defined in your struts-config.xml.

现在还可以在设置器上使用@Autowired将其他bean注入到Action类中.

It's now also possible to have other beans injected into you Action class with @Autowired on setter(s).

这篇关于如何将旧的Struts应用程序与Spring 3.x集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆