Mar*_*rco 5 integration spring struts inversion-of-control
我想知道如何以及将Spring Strx 1.x应用程序与Spring 3.x集成的首选方法,以便我们可以从IOC中获益.
使用ContextLoaderPlugin并将struts控制器设置为processorClass" AutowiringRequestProcessor ",如下所示(在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>
Run Code Online (Sandbox Code Playgroud)
action-servlet.xml必须是空bean上下文文件:
<beans></beans>
Run Code Online (Sandbox Code Playgroud)
将以下init参数添加到web.xml中的ActionServlet:
<init-param>
<param-name>autowire</param-name>
<param-value>byName</param-value>
</init-param>
Run Code Online (Sandbox Code Playgroud)
只需编写常规的struts动作,并在每个动作中添加注释"@Component",以便spring发现动作并从中创建一个bean."AutowiringRequestProcessor"将找到与struts-config.xml中定义的动作类相匹配的正确bean.
现在也可以在setter上使用@Autowired将其他bean注入到Action类中.
| 归档时间: |
|
| 查看次数: |
13790 次 |
| 最近记录: |