Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate an old Struts application with Spring 3.x

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.

like image 431
Marco Avatar asked Apr 29 '11 18:04

Marco


People also ask

Which integrates with existing frameworks like Spring MVC Struts and JSF in both servlet and portlet environment?

SWF integrates with existing frameworks like Spring MVC, Struts, and JSF, in both servlet and portlet environments. If you have a business process (or processes) that would benefit from a conversational model as opposed to a purely request model, then SWF may be the solution.


2 Answers

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 has to be an empty beans context file:

<beans></beans>

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>

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.

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

like image 65
Joep Avatar answered Sep 27 '22 21:09

Joep


Use ContextLoaderPlugIn. Deprecated in Spring 3.0, but still there.

I used it with Struts 1.x and Spring 2.5.x - it worked beautifully. This integration approach allows to inject Spring beans directly into Struts actions, which is pretty clean and straightforward.

like image 36
Tomasz Nurkiewicz Avatar answered Sep 27 '22 23:09

Tomasz Nurkiewicz