struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jake Vang <vangj...@googlemail.com>
Subject Re: spring, struts2, convention plugin, how to "wire" an action class
Date Fri, 14 May 2010 00:18:34 GMT
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.varley@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-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


Mime
View raw message