struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <>
Subject Re: Constructor with arguments
Date Tue, 03 Jun 2008 19:34:18 GMT
You don't need an XML file per class, just an entry per class in one XML 
file -- and if you use Spring 2.5's @Ccomponent/@Resource annotation 
support, you don't even need that. If you have Spring deployed anyway, 
it's definitely the best tool for the job here.


Alberto A. Flores wrote:
> Thanks Brian,
> Yes, I'm using Spring already. The way I fixed it was by having Spring 
> instantiate the class (I wasn't doing that before). Problem was that now 
> I need to maintain an additional XML file (for each class) which is what 
> I was trying to avoid.
> Spring will do for me for now.
> Relph,Brian wrote:
>> The struts2 object factory uses xwork's object factory to create the 
>> actions:
>> public Object buildAction(String actionName, String namespace, 
>> ActionConfig config, Map extraContext) throws Exception {
>>         return buildBean(config.getClassName(), extraContext);
>>     }
>> Which, as you can guess, can only build object with public,no-arg 
>> constructors.
>>     public Object buildBean(Class clazz, Map extraContext) throws 
>> Exception {
>>         return clazz.newInstance();
>>     }
>> There is a SpringObjectFactory available in xwork, which was extended 
>> in the spring plugin as the StrutsSpringObjectFactory.  These allow 
>> you to use spring to configure your actions, which if you don't mind 
>> autowiring-by-name, does not require any special work on your part.
>> When you say you rely on spring to build your actions, are you already 
>> using the spring plugin?  I find it works well, and since I use spring 
>> for so many other things, I have no need to get rid of it as a 
>> dependency.  If you don't want to use spring, you can create your own 
>> object factory, and override either the buildAction or buildBean 
>> methods to handle other constructors.  It seems like you will still 
>> need to find your constructor argument objects from somewhere though, 
>> so wouldn't you need some DI framework to handle that anyway?
>> I think there is work being done to adopt Guice as the default DI 
>> framework, you could look into that.
>> Brian Relph
>> -----Original Message-----
>> From: Alberto A. Flores [] Sent: Tuesday, 
>> June 03, 2008 10:36 AM
>> To: Struts Users Mailing List
>> Subject: Constructor with arguments
>> Does anyone know how to make Struts2 ObjectFactory instantiate actions 
>> with constructor-arguments.
>> I currently have to rely on Spring to handle that case, but would be 
>> nice to do it without it.
> ------------------------------------------------------------------------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message