Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 82597 invoked from network); 14 May 2010 00:43:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 May 2010 00:43:28 -0000 Received: (qmail 12186 invoked by uid 500); 14 May 2010 00:43:25 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 12161 invoked by uid 500); 14 May 2010 00:43:25 -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 12153 invoked by uid 99); 14 May 2010 00:43:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 May 2010 00:43:25 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of denis.cabasson@gmail.com designates 209.85.212.48 as permitted sender) Received: from [209.85.212.48] (HELO mail-vw0-f48.google.com) (209.85.212.48) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 May 2010 00:43:19 +0000 Received: by vws6 with SMTP id 6so1688589vws.35 for ; Thu, 13 May 2010 17:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=ckKsS1LR+vJ8o42ghF5zLinDVNQufUJUPTDt2Zx9tQo=; b=B6qdKVq9ZZkaAlR5Jewr161EpUEWax5JcybpC3WyWjocBgXQRDrfMvogDUkx3G5aoN QHvCJwcRzLCCCxLNqRqzc60G6jNZNiOuVdUADGHIyv6TXT0luHWuVyg0hNO7QrYlnFVF djiEfbxAqqp3KuX58sO0UIb70ZVkg+mc5aSKA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; b=sTv6e4swEPPFEj5jmXvib9/pzftCJD9kP9WSUKdS0cDj6k47A9DHs21AqELSI61Qcd Ik+oXINoj53As69JoFqEoeExjrMPbP/6etfYFmz0L9FL5Wtla0noS3GB8FukMyZbSI90 s3CA5nNmqB+oe4uVB/Y1yxZPgczWg/G5eE4iM= Received: by 10.220.108.79 with SMTP id e15mr193445vcp.21.1273797777789; Thu, 13 May 2010 17:42:57 -0700 (PDT) Received: from [192.168.0.100] (CPE0022152433c0-CM001a666aaa3e.cpe.net.cable.rogers.com [99.245.232.112]) by mx.google.com with ESMTPS id x6sm7915739vco.23.2010.05.13.17.42.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 13 May 2010 17:42:55 -0700 (PDT) Message-ID: <4BEC9C8F.5010005@gmail.com> Date: Thu, 13 May 2010 20:42:55 -0400 From: Denis Cabasson Reply-To: denis.cabasson@gmail.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: user@struts.apache.org Subject: Re: spring, struts2, convention plugin, how to "wire" an action class References: <4FDDA327A6C64D4BB6B4670122AA8D4202265001@lonex01.weComm.local> <4FDDA327A6C64D4BB6B4670122AA8D4202265004@lonex01.weComm.local> <4FDDA327A6C64D4BB6B4670122AA8D420226500B@lonex01.weComm.local> <28546598.post@talk.nabble.com> <28547552.post@talk.nabble.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org My best guess is that the Action instance used in the web application is not actually loaded from the configuration in your applicationContext, but directly by Struts 2 (through the Spring Factory, but still Struts 2). That mean that you will have a bean named myAction in you application context, but that is not the bean that will actually be used by Struts to serve your request. Struts will create another instance, which won't have any of your configuration. This different instance is then autowired by type (defaut behaviour) which means your service (configured in your context) gets injected because it has the right type. I can't actually confirm that behaviour, but that seems like the likely explanation. I will be able to double check tomorrow. To check that, I can recommend 2 things : * Set the autowiring to be by name, create 2 beans named verbose and message, and see how that works * Leaving the autowiring by type, create 2 instances of your service, and my best guess is that Struts will crash, unable to decide between the 2 I think what your are missing is the fact that while struts uses Spring to manage the lifecycle of its action, it doesn't use the action defined in your application context, but will load its own instances, and autowire them. Denis. Le 2010-05-13 20:18, Jake Vang a �crit : > roger, > > thanks for the steps. i went through each of those steps and made sure > my settings/configurations complied. however, i still cannot > initialize Action classes using Spring. > > as an illustration of the problem i am facing, i have created an > example that you may download and verify for yourself that this does > not work. > > http://www.box.net/shared/iycamr9uo6 > > this will download a zip file with an Eclipse project; unzip it. if > you have Ant, you simply type in "ant war" and the war file will be > created. if you have Tomcat, then drop the war file into the webapps > directory (assuming you have Tomcat 6.0). > > if you go to http://localhost:8080/myapp/, you will see four lines displayed. > String from Action: default > boolean from Action: false > String from Service: overwritten > boolean from Service: true > > The first and second lines confirm that the String and boolean values > are not injected into the Action class. The third and fourth lines > confirm that the String and boolean values are injected into the > service class. > > thanks. > > On Thu, May 13, 2010 at 9:32 AM, RogerV wrote: > >> >> >> Jake Vang wrote: >> >>> >>>> If you want Spring to create your action class (as opposed to Struts >>>> creating them) then you need to define your action in the >>>> applicationContext.xml file. >>>> >>> how do you do that? here's a couple of ways i have tried that do NOT work. >>> >>> >> 1) Add> value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> to your >> struts.xml file. >> >> 2) Add >> >> org.springframework.web.context.ContextLoaderListener >> >> >> to your web.xml >> >> 3) Make sure that you have the Struts2 Spring plugin installed. >> >> 4) Put something along the lines of >> > scope="prototype"/> (The scope prototype is important otherwise Spring >> creates a singleton rather than a new action on each invocation which is >> what Struts 2 expects) >> >> and that should get Spring instantiating your action classes for you. >> >> Although I'm guessing from your response you've already got to that stage. >> >> I'm not sure that I understand what you are trying to acheive with >> >> >> >> >> >> If you're trying to inject another class, then the format is on the lines of >> >> >> >> >> >> where you need a setter that matches the name parameter (setClassA(ClassA >> classA)) in MyAction. The ref value points to another> class="com.services.classA"/> >> >> HTH and I haven't completely misunderstood what you are trying to do. >> >> Regards >> >> >> -- >> View this message in context: http://old.nabble.com/spring%2C-struts2%2C-convention-plugin%2C-how-to-%22wire%22-an-action-class-tp28545412p28547552.html >> Sent from the Struts - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org >> For additional commands, e-mail: user-help@struts.apache.org >> >> >> > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org