struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alberto A. Flores" <aaflo...@gmail.com>
Subject Re: Injecting Spring Services into Struts 2 Actions
Date Thu, 08 May 2008 14:25:43 GMT
Related to this question, I'm leveraging Spring's use of the @Resource 
annotation to the private member variable (no setter needed), thus fully 
relying on Spring's injection mechanism. I supposed it all depends on 
tight coupling to Spring you want to add.

Relph,Brian wrote:
> The actions are auto-wired by name by default - so if any of its properties match bean-ids
in your spring config, and they have setters, then those properties will get set.
> 
> The part about declaring the dependencies means you disable the auto-wiring, and declare
your actions as spring beans. So, instead of this:
> 
>         <action name="index"
>             class="com.actions.IndexAction">
>             <result>/WEB-INF/view/index.jsp</result>
>         </action>
> 
> You would do this:
> 
>         <action name="index"
>             class="index-action-id">
>             <result>/WEB-INF/view/index.jsp</result>
>         </action>
> 
> Along with additional spring config:
> 
>     <bean id="index-action-id"
>         class="com.actions.IndexAction">
>         <property name="myDao" ref="myDao-id" />
>         <property name="myMailSender" ref="myMailSender-id" />
>     </bean>
> 
> Notice this does not actually disable auto-wiring (you would have to set the auto-wire
attribute in the spring config, either globally or per-bean), but it does declaratively state
what to set on the action as properties.
> 
> Brian Relph
> 
> -----Original Message-----
> From: Asleson, Ryan [mailto:asleson@BIWORLDWIDE.com] 
> Sent: Thursday, May 08, 2008 8:29 AM
> To: Struts Users Mailing List
> Subject: Injecting Spring Services into Struts 2 Actions
> 
>  
> 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 Struts 2 Action does not
need to be registered with Spring.  So far so good.
>  
> However, I'm a little unclear as to how exactly it "knows" what Spring beans to inject
into the Struts 2 Action.  Assuming I have a Struts 2 Action 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 be used for injecting a
Spring bean?  Imagine that the Struts 2 Action has several "set" methods, and that there are
a number of configured Spring beans.
> 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 Spring bean, especially if there are a lot of Spring
beans (and there usually are).
>  
> The document above includes this comment:
>  
> We strongly recommend that you find declarative ways of letting Spring know what to provide
for your actions.
>  
> But it doesn't give an example of how to let Spring know what to provide to the actions.
>  
> So, the question is:  How do I tell Spring what beans need to be injected into the Action?
>  
> Thanks!!!!
>  
> -Ryan
>  
>  
> 
> This e-mail message is being sent solely for use by the intended recipient(s) and may
contain confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by phone
or reply by e-mail, delete the original message and destroy all copies. Thank you.
> 
> ----------------------------------------------------------------------
> CONFIDENTIALITY NOTICE This message and any included attachments are from Cerner Corporation
and are intended only for the addressee. The information contained in this message is confidential
and may constitute inside or non-public information under international, federal, or state
securities laws. Unauthorized forwarding, printing, copying, distribution, or use of such
information is strictly prohibited and may be unlawful. If you are not the addressee, please
promptly delete this message and notify the sender of the delivery error by e-mail or you
may call Cerner's corporate offices in Kansas City, Missouri, U.S.A at (+1) (816)221-1024.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

-- 

Alberto A. Flores
http://www.linkedin.com/in/aflores



Mime
View raw message