Frank,

AFAIU, you want your Business Service Object to be injected in your Struts2
actions. To achieve that, I have done this:

- Using Spring ObjectFactory.
- Declare Business Service Object (BSO) in Spring's
applicationContext.xml(you've already done that)
- Define action that has setter method for your BSO.
- Declare this action as a <bean> in applicationContext.xml, with BSO
injected as dependency.

Sample Code:

Action:

public class SetEndPoint extends ActionSupport {
    private DispatcherService dispatcherService;
    public String execute () throws Exception {
            //-----your business logic-----
            return SUCCESS;
    }

    // DispatcherService object will be set (i.e. injected) by Spring (see
applicationContext.xml)
    *public void setDispatcherService(DispatcherService dispatcherService)*{
        this.dispatcherService = dispatcherService;
    }
}

applicationContext.xml

         <!-- ..... your existing bean declaration for DispatcherService
remains .... ->

    <!-- ..... Declare action here, injecting DispatcherService .... ->
    <bean id="setEndPoint" class="example.client.web.action.SetEndPoint">
        *<property name="dispatcherService">*
            <ref bean="DispatcherService"/>
        </property>
    </bean>

struts.xml

<struts>
    *<constant name="struts.objectFactory" value="spring" />*
    <package name="no.bbs" extends="struts-default">
        <action name="setEndPoint" method="execute" *class="setEndPoint"* >
            <result name="consumeA">/view/consumeAcos.jsp</result>
            <result name="consumeB">/view/consumeMapp.jsp</result>
            <result name="error">/view/error.jsp</result>
        </action>
    </package>
</struts>

I have underlined important parts of each artifact..
I hope this helps..

-Rushikesh

On Mon, Mar 17, 2008 at 5:28 PM, Piero Sartini <[EMAIL PROTECTED]>
wrote:

> Am Donnerstag, 13. März 2008 22:32:34 schrieb Frank Fischer:
> > Now i don't understand (1) where to create/initialize these business
> logic
> > classes and (2) how to get access to them from the action classes.
>
> Just build your business logic without thinking about s2 too much. From
> your
> action classes you can access your business logic like everything else.
> Its
> really more of a java problem how to do this =)
>
> If you have to run initialization code at startup, maybe a normal Listener
> is
> what you are looking for...
>
>        Piero
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to