Laurie Harper
Fri, 09 May 2008 00:15:17 -0700
L. Dave Newton wrote:
Is this a Spring 2.5 thing? I'm not using 2.5 yet and haven't had to do anything to get my actions to be injected with Spring beans (at least I don't think so; I remember having to set the object factory to "spring" in earlier days?) Dave --- Laurie Harper <[EMAIL PROTECTED]> wrote:Asleson, Ryan wrote:Hello, I found this guide to injecting Spring beans into Struts 2 Actions: http://cwiki.apache.org/WW/spring.html According to the red box at the bottom of the document, the Struts2Er, that's not as clear as it could be; I believe it means that 'registering Actions with Spring is not required *if you don't want Spring dependency injection for that action*'. In other words, you *do* need Spring to know about the action if you want it to injectAction does not need to be registered with Spring. So far so good.dependencies.However, I'm a little unclear as to how exactly it "knows" whatSpringbeans to inject into the Struts 2 Action. Assuming I have a Struts2Action that depends on a PersonService, I assume that the Struts 2 Action would have a public mutator for the PersonService like this:public void setPersonService(PersonService service) {this.personService = service; }How does the injection system "know" that this method should beused forinjecting a Spring bean? Imagine that the Struts 2 Action hasseveral"set" methods, and that there are a number of configured Springbeans.It would take way too long for the injection system to look through every "set" method on the Action and try to find a matching Springbean,especially if there are a lot of Spring beans (and there usuallyare).The document above includes this comment: We strongly recommend that you find declarative ways of lettingSpringknow what to provide for your actions.But it doesn't give an example of how to let Spring know what toprovideYou can either configure the action as a Spring bean in your applicationContext.xml and use the normal declarative syntax to do this, or you can use Spring 2.5's @Component, @Resource, etc. annotations and skip the XML. But you do need to do one or the other.to the actions.So, the question is: How do I tell Spring what beans need to beinjected into the Action?L. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]