Tuesday, March 31, 2009

Using Spring Container to instantiate Struts Action Classes

In Spring ApplicationContext.xml add this

<bean id="personAction" scope="prototype" class="quickstart.action.PersonAction">
<constructor-arg ref="personService">

This is the instance of the action class which needs to be created .

In Struts struts.xml add this

<constant name="struts.objectFactory" value="spring">

This ensures the struts spring integration

Add this also

<action name="xxx" method="yyy" class="personAction">
<result name="input">pages/list.jsp</result>

In the above configuration, in the class field the name of the spring bean is
directly mentioned.

By doing so the spring container creates the action class instance for struts which is a prototype.

An other alternative to do the same is using Aspect J Weaving.

Free Domain Names @ .co.nr!