struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Cook" <James.C...@wecomm.com>
Subject RE: Struts 2 Spring Plugin Usage
Date Tue, 03 Nov 2009 13:16:14 GMT
The spring plugin will look by default auto wire your spring beans via
type, it isn't tied to the getXXX(); method call. I myself only have the
declaration and a setter, the autowiring injects the spring managed bean
for me.

Nothing is done with the getters....

DAO Class:

public MyDAOImpl implements MyDAO...

Service Class:

public MyServiceImpl implements MyService {

private MyDAO myDAO;

public void setMyDAO(MyDAO myDAO) {
	this.myDAO = myDAO;
}
.....

Action:

public MyAction extends ActionSupport {

private MyService myService;

public void setMyService(MyService myService) {
	this.myService = myService;
}
.....

appContext.xml

<bean id="myService" class="com.mypackage.service.impl.MyServiceImpl" >
	<property name="myDAO" ref="myDAO" />
</bean>

<bean id="myDAO" class="com.mypackage.dao.impl.MyDAOImpl" />
.....

I hope my example helps in some way...


-----Original Message-----
From: Roger Varley [mailto:roger.varley@googlemail.com] 
Sent: 03 November 2009 12:49
To: Struts Users Mailing List
Subject: Re: Struts 2 Spring Plugin Usage

>
> I use the convention plugin for Struts and I take advantage of the
> spring auto wiring (by name) to automagically inject my service layer.
> You can do the same for the rest. Check out the reference guide over
at
> spring framework to do so. Weirdly I like having my DAO and Service
> classes in the appcontext xml file.. But then that is because I am
> weird...
>

Either I'm misunderstanding the responses or I'm not being clear (I'm
also using the convention plugin along with the Spring plugin.)

<bean id="securityManager" class="com.myApp.security.PasswordChecker"
/> is sufficient to have the PasswordChecker injected everywhere any
action contains a getSecurityManager() method.

However if my PasswordChecker also has need of injection to access a
database (ie. PaswordChecker contains a getDaoManager() method then
simply having

<bean id="securityManager" class="com.myApp.security.PasswordChecker" />
<bean id="daoManager" class="com.myApp.security.DaoManager"/>

in the application.context.xml does not appear to be sufficient. My
action is injected with the PasswordChecker, but the PasswordChecker
is not injected with the DaoManager.

Regards

---------------------------------------------------------------------
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