Linking Struts and Spring with DelegatingActionProxy

No Gravatar

Struts is great for a generic MVC framework for J2EE apps.
Spring is great for it’s inversion of control capabilities, as well as many other fantastically useful features.
But … what happens when you want to link them? Well, my favorite way to do this is via the DelegatingActionProxy in Spring’s API. Essentially, you follow these steps:
1. Setup struts to know where spring is:


<plug-in classname="org.springframework.web.struts.ContextLoaderPlugIn">
	<set-property property="contextConfigLocation"
		value="/WEB-INF/applicationContext.xml" />
</plug-in>

2. Setup your action in struts to use the DelegatingActionProxy


<action path="/admin/myAction1"
	type="org.springframework.web.struts.DelegatingActionProxy"
	parameter="myAction1" name="MyForm" scope="request"
	input="/admin/home.do" validate="false">
    <forward name="success" path="/admin/myAction2.do" />
</action>

3. Configure an action in spring to link the action path to the appropriate struts action class


<bean name="/admin/myAction1" class="com.some.MyAction">
    <property name="myDA">
        <ref bean="myDA" />
    </property>
</bean>

That’s it! Now you’ve hooked up struts and spring successfully and cleanly. If you’d like more alternatives and information, this link can help out.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *