struts 2 action flows

and “All objects in this architecture (Actions, Results, Interceptors, and so forth) are created by an ObjectFactory. This ObjectFactory is pluggable. We can provide our own ObjectFactory for any reason that requires knowing when objects in the framework are created. A popular ObjectFactory implementation uses Spring as provided by the Spring Plugin.”

Besides, for dependency injection, it’s generally referred as, “instead of creating its own required objects, object creation would be done by an object factory.”

For struts, spring integration, using struts-spring plugin, the struts.objectFactory is configured to use the spring object factory as in the struts-plugin.xml. nothing needs to be configured( unless special requirements), other than simply put the struts-spring plugin jar in class path.

for this integration, or DI, or IoC, whatever called, possible usage examples are,


<action name=”check” class=”checkActionClass” ….>


Spring applicationContext.xml

<bean id=”checkActionClass”…..>


which would wire the object, initialized using spring object factory, or framework(till now, i m still not that clear about those concepts, many more books to read).


<action name=”check” class=”whatever(either wired through struts internal auto-wiring, or spring framework, depends on whether its been defined in spring bean definitions, since that’s the priotiry)”/>

while inside this “whateve” action class, its constructors would be initialized first, then followingly, all setter methods conducted!! again, priority goes to spring first.

for example, if there is one property inside the action class, like

class WhateverActionClass{


InterfaceServiceA serviceA;

//methods, using the serviceA method update DB

//setters, set the sevriceA


spring, application-context.xml

<bean id=”serviceA” …./>

after initilization of the whateverActionClass, all its properties setters methods would be called, and set using the bean definitions which has bean id same as its property name; due to the default auto-wiring is byName.


add on, to this DI, or IoC,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s