Here is a tutorial on how to use Webwork(works the same on Struts 2)
with Spring:
http://www.opensymphony.com/webwork/wikidocs/Spring.html
just set:
<constant name="struts.objectFactory" value="spring" />
in your struts.xml instead of "webwork.objectFactory ".
regards
musachy
Nuwan Chandrasoma wrote:
Hi Peder,
As for my knowledge Spring 2 support this scoped variables, but i dont
have an idea of how to use it with struts2
Regards,
Nuwan
----- Original Message ----- From: "Peder Larsen"
<[EMAIL PROTECTED]>
To: <user@struts.apache.org>
Sent: Thursday, December 21, 2006 5:05 PM
Subject: How to use IoC in struts2?
Hi, i've got one very basic question that i cant find any
documentation for
nor any examples, maybe i've missed it but..
What i want to is to inject a UserInfo object into my action. In
webwork2
you used components.xml for this. E.g,
<component>
<scope>session</scope>
<class>foo.acme.UserInfo</class>
<enabler>foo.acme.UserInfoAware</enabler>
</component>
to tell the IoC framework (is it xwork?) to inject the UserInfo into any
Action implementing UserInfoAware.
Now, I've managed to inject it in struts2 as well, but i cant find a
way to
inject ONE UserInfo pr session, i can only specify singleton="true" or
"false" in "applicationContext.xml".
I paste my struts.xml and applicationContext.xml here so a more
enlightened
soul may give me some clue,
struts.xml,
<?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="unrestrictedActions" extends="struts-default" >
<interceptors>
<interceptor name="login" class="
foo.acme.interceptor.LoginInterceptor"/>
<interceptor-stack name="secureStack">
<interceptor-ref name="login"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack"/>
<action name="index" class="indexAction">
<result type="freemarker">/ftl/index.ftl</result>
</action>
</package>
</struts>
applicationContext.xml,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="userInfo" class="foo.acme.UserInfo"
singleton="false"></bean>
<bean id="indexAction" class="foo.acme.actions.IndexAction"
singleton="false">
<property name="userInfo"><!-- THIS INJECTS THE USERINFO BUT IT
INJECTS A NEW EVERY REQUEST, WANT 1 PR SESSION -->
<ref local="userInfo" />
</property>
</bean>
</beans>
Maybe theres an altogether better way of setting up the IoC in
struts2? Im
all ears.
Best regards, Peder Jensen.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]