struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "MK Tan" <mktan...@gmail.com>
Subject Re: [S2] Spring Injection
Date Wed, 23 May 2007 16:04:16 GMT
Hi,
Let assume your base class is like this:
public class BaseAction extends ActionSupport {
    private MyService myService;
    public void setMyService(MyService service) {
        this.myService = service;
    }

    //put others getter and setter here...
}

public class FooAction extends BaseAction {
//do whatever you want with myService
}

public class BarAction extends BaseAction {
//create anything you like with myService
}

in your applicationContext.xml, declare something shown below:
<bean id="baseAction" class="your.package.name.BaseAction" abstract="true">
    <property name="myService" ref="myService"/>
</bean>

<bean id="fooAction" class="your.foo.package.name.FooAction"
parent="baseAction"/>
<bean id="barAction" class="your.bar.package.name.BarAction"
parent="baseAction"/>


HTH
MK Tan
On 5/23/07, Roger Varley <roger.varley@googlemail.com> wrote:
>
> Hi
>
> I suspect that this going to be a stupid question but please bear with
> me. I have a BaseAction for my application that extends ActionSupport
> and all my actions extend BaseAction. BaseAction recieves a reference
> to a Service bean, through which my actions obtain objects from my
> Business Layer, by injection from the Spring container.
>
> Is there a way of configuring Struts and Spring so that I only need to
> do this for my BaseAction  and therefore avoid having to define all my
> actions to Spring or do I still need to inject the Service object into
> each action.
>
> I'm sorry if this is a really stupid question, but this is all new stuff
> to me.
>
> Regards
> Roger
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message