Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 30088 invoked from network); 8 May 2008 16:57:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 May 2008 16:57:59 -0000 Received: (qmail 5365 invoked by uid 500); 8 May 2008 16:57:50 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 5341 invoked by uid 500); 8 May 2008 16:57:50 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 5330 invoked by uid 99); 8 May 2008 16:57:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 May 2008 09:57:50 -0700 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jak-struts-user@m.gmane.org designates 80.91.229.2 as permitted sender) Received: from [80.91.229.2] (HELO ciao.gmane.org) (80.91.229.2) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 May 2008 16:56:56 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Ju9Qk-0005QK-BQ for user@struts.apache.org; Thu, 08 May 2008 16:57:18 +0000 Received: from cpe0016b5ef7ea1-cm0014e88ef4b4.cpe.net.cable.rogers.com ([99.233.20.4]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 08 May 2008 16:57:18 +0000 Received: from laurie by cpe0016b5ef7ea1-cm0014e88ef4b4.cpe.net.cable.rogers.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 08 May 2008 16:57:18 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: user@struts.apache.org From: Laurie Harper Subject: Re: Injecting Spring Services into Struts 2 Actions Date: Thu, 08 May 2008 12:57:07 -0400 Lines: 49 Message-ID: References: <6360445556B02A4BB76993AD583BF97DEE04D9@EXCHANGE2.biperf.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: cpe0016b5ef7ea1-cm0014e88ef4b4.cpe.net.cable.rogers.com User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) In-Reply-To: <6360445556B02A4BB76993AD583BF97DEE04D9@EXCHANGE2.biperf.com> Sender: news X-Virus-Checked: Checked by ClamAV on apache.org 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 Struts 2 > Action does not need to be registered with Spring. So far so good. Er, 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 inject dependencies. > 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? You 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. L. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org