Lukasz Lenart wrote:
> Exactly, first, Struts (default object factory) will
> create action object and then it will *ask* Spring
> to inject depended beans, base on applicationConfig.xml.
> I'm just wondering, if there any drawbacks for this?

The only one I can think of is that your actions wouldn't actually be Spring 
managed, so they wouldn't be available for AOP.

The Spring2-Spring plugin will first ask Spring for the action, then, if it's 
not found, the Struts2-Spring plugin will create the action and have it 
autowired with other Spring beans (as you and Dave have mentioned).

An alternative that I'm currently enjoying is what I call zero-config Spring 
and Struts 2. I don't define any Actions in applicationContext.xml nor do I 
define any actions in struts.xml. Spring 2.5 has some incredible classpath 
scanning features, where you can annotate your Spring beans (including Actions) 
with @Component or @Repository, etc, and Spring can pick them up automatically. 
Even better than that, if you have a particular package that you put all your 
actions in, you can tell Spring to configure a bean for each class in that 
package, so you don't even have to annotate those classes.

Combine the above with zero-config and the code behind plugin for Struts 2 
(plus a little bit of magic [1]) and you can have a wonderful environment where 
Spring and Struts pick everything up on their own (meaning, no xml to edit each 
time you want to add an action, DAO, etc.)

[1] https://issues.apache.org/struts/browse/WW-2558#action_43525

Brad Cupit
Louisiana State University - UIS

Reply via email to