BeanNameAware Interface to be implemented by beans that want to be aware of their bean name in a bean factory. Note that it is not usually recommended that an object depend on its bean name, as this represents a potentially brittle dependence on external configuration, as well as a possibly unnecessary dependence on a Spring API
//where does your Bean class MyService implement BeanNameAware? public interface BeanFactory The root interface for accessing a Spring bean container. This is the basic client view of a bean container; further interfaces such as ListableBeanFactory and ConfigurableBeanFactory are available for specific purposes. This interface is implemented by objects that hold a number of bean definitions, each uniquely identified by a String name. Depending on the bean definition, the factory will return either an independent instance of a contained object (the Prototype design pattern), or a single shared instance (a superior alternative to the Singleton design pattern, in which the instance is a singleton in the scope of the factory). Which type of instance will be returned depends on the bean factory configuration: the API is the same. Since Spring 2.0, further scopes are available depending on the concrete application context (e.g. "request" and "session" scopes in a web environment). //where does you Bean class implment BeanFactory? //applicationContext.xml <bean id="myAction" class="com.vang.jake.web.actions.MyAction" scope="singleton"> <property name="verbose" value="${verbose}"/> <property name="message" value="${message}"/> <property name="myService" ref="myService"/> </bean> package com.vang.jake.services; public class MyService { private boolean verbose = false; private String message = "default"; public boolean isVerbose() { return verbose; } public void setVerbose(boolean verbose) { this.verbose = verbose; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } } ? Martin Gainty ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. > Date: Thu, 13 May 2010 20:18:34 -0400 > Subject: Re: spring, struts2, convention plugin, how to "wire" an action class > From: vangj...@googlemail.com > To: user@struts.apache.org > > 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 <roger.var...@googlemail.com> 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 <constant name="struts.objectFactory" > > value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> to your > > struts.xml file. > > > > 2) Add <listener> > > > > <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> > > </listener> > > > > to your web.xml > > > > 3) Make sure that you have the Struts2 Spring plugin installed. > > > > 4) Put something along the lines of > > <bean id="myAction" class="com.somwhere.mypackage.MyAction" > > 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 > > > > <bean name="/action" class="com.services.MyAction"> > > <property name="propertyA" value="${propertyA}"/> > > </bean> > > > > If you're trying to inject another class, then the format is on the lines of > > > > <bean name="/action" class="com.services.MyAction"> > > <property name="classA" ref="classA"/> > > </bean> > > > > where you need a setter that matches the name parameter (setClassA(ClassA > > classA)) in MyAction. The ref value points to another <bean id="classA" > > 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-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > _________________________________________________________________ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4