You also need to setup your action in the application context so that Spring knows where to inject the business object. Your class name in the Struts action also needs to be the *bean id of the action* so that the Struts/Spring plugin can do it's work. So assuming you have a setter for DispatcherService in CustomerAction your struts.xml would look like this.
> <struts> > > <package name="customerAgent" extends="struts-default"> > > <action name="login" method="login" class="customerAction"> > <result name="input">/CustomerLogin.jsp</result> > <result name="success">/CustomerChat.jsp</result> > </action> ... Application context: ... <bean id="customerAction" class="com.demo.CustomerAction"> <property name="DispatcherService" ref="DispatcherService"/> </bean I recommend making your bean id's lower case and lower case properties in the Action. Private DispatcherService dispatcherService; Then the property would be <property name="dispatcherService" ref="dispatcherService"/> Regards, Randy Burgess Sr. Web Applications Developer Nuvox Communications > From: Frank Fischer <[EMAIL PROTECTED]> > Reply-To: Struts Users Mailing List <user@struts.apache.org> > Date: Mon, 17 Mar 2008 17:08:30 +0100 > To: 'Struts Users Mailing List' <user@struts.apache.org> > Subject: RE: How to initialize business service objects? > > > Hi all > > first i'd like to thank all of you that have given me valuable feedback to > my question. > > Following the answers from Dave and Jeromy i decided to go the "hard" way > with Spring and DI. After reading some manuals (thanks to GF, good reading) > i managed to load the Spring ContextLoaderListener and even define an POJO > bean that serves as my BusinessLogicService. From the Tomcat logs i can see > that an instance of that Service is created. > > As far as i read/unterstood, i now would only have to create a setter method > on my Action class and Spring then would automatically inject the related > dependcy to my Action class. So far, this doesn't seem to work, so i guess, > i must be missing something. > > My applicationContext.xml looks quite simple (and seems to work, since the > DispatcherService is created on startup): > > ----------- > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" > "http://www.springframework.org/dtd/spring-beans.dtd"> > <beans default-autowire="autodetect"> > <bean id="DispatcherService" > class="com.demo.businesslogic.DispatcherService"/> > </beans> > ----------- > > The Struts config looks like: > > ----------- > <?xml version="1.0" encoding="UTF-8" ?> > <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts > Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> > > <struts> > > <package name="customerAgent" extends="struts-default"> > > <action name="login" method="login" class="com.demo.CustomerAction"> > <result name="input">/CustomerLogin.jsp</result> > <result name="success">/CustomerChat.jsp</result> > </action> > > <action name="logout" method="logout" > class="com.demo.CustomerAction"> > <result name="success">/CustomerLogin.jsp</result> > <result name="input">/CustomerLogin.jsp</result> > </action> > > <action name="chat" method="chat" class="com.demo.CustomerAction"> > <result name="success">/CustomerChat.jsp</result> > </action> > > > </package> > > </struts> > ----------- > > So i guess, i must be missing something. Is there a way i would have to tell > Spring which Action classes to inject? > > Thanks a lot for your help > Frank > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > This email and any attachments ("Message") may contain legally privileged and/or confidential information. If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email. Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]