|
From: James C. <jim...@do...> - 2004-05-12 13:34:41
|
There was a thread last week that introduced the AutowireByInterface
approach and how it's different from autowire="byType".
Primarily, autowire="byType" is an all or nothing approach. If I mark a bean
this way, any setter on my bean will get wired if there is a matching bean
type in Spring. There are a couple drawbacks to this approach that are
discussed in the reference docs, but for me, I just want to be more explicit
in my wiring needs. I don't want a getAge(int) method on one of my beans
accidentally getting wired up to some constructor argument that I may have
in my Spring configuration.
The AutowireByInterface allows me to use the following configuration:
<bean id="SecuritySAO" class="my.sao.SecuritySAOImpl" />
<bean id="SecuritySAOAware" class="my.spring.AutowireByInterface">
<property
name="interface"><value>my.aware.SecuritySAOAware</value></property>
<property name="property"><value>securitySAO</value></property>
<property name="value"><ref bean="SecuritySAO" /></property>
</bean>
<bean id="MyAccountAction" class="my.webwork.MyAccountAction"
singleton="false" />
If I load 'MyAccountAction' from Spring, the SecuritySAO class is wired on
only if my.webwork.MyAccountAction implements the my.aware.SecuritySAOAware
interface. This makes it vary declarative, and requires no configuration
(other than adding the AutowireByInterface bean post processor). It has all
of the advantages of autowire by type, and none of the disadvantages. It is
really working well for us.
_____
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Dmitriy Kopylenko
Sent: Tuesday, May 11, 2004 10:56 PM
To: spr...@li...
Subject: Re: [Springframework-developer] Bean not advised because another
dependency grabs it first?
I'm just trying to understand what is the purpose of
my.spring.AutowireByInterface class? Why not just use 'autowire="byType"'
attribute of beans needing SecuritySAO dependency?
Regards,
Dmitriy.
James Cook wrote:
I'm experiencing a problem with the order that my beans are wired together.
I have an SAO bean (id=SecuritySAO) and it is a singleton.
I want this bean to be advised by a BeanNameAutoProxyCreator so it will be
control transactions.
I also want this bean to be wired into another BeanPostProcessor class I
wrote called SAOAware.
The problem is that the SecuritySAO bean is created initially be the
SAOAware bean because it is a property of the latter. This means that the
AutoProxy bean has not yet had an opportunity to work its magic on the bean
and proxy it.
When I use the SAOAware bean, the SecuritySAO object is not proxied and not
weaved into the transation interceptor. I have tried to use the depends-on
to cause the AutoProxy to instrument the bean first, but it didn't make any
difference. I have also used the ordered property of both post processors
without any effect also.
Am I missing something else?
<bean id="SecuritySAO" class="my.SecuritySAOImpl" />
<bean id="AutoProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"
<property name="proxyTargetClass"><value>true</value></property>
<property name="order"><value>1</value></property>
<property name="interceptorNames">
<list>
<idref local="transactionInterceptor"/>
</list>
</property>
<property name="beanNames">
<list>
<idref local="jpp.SecuritySAO"/>
</list>
</property>
</bean>
<bean id="SAOAware" class="my.spring.AutowireByInterface"
depends-on="AutoProxy">
<property name="order"><value>100</value></property>
<property name="interface"><value>my.SAOAware</value></property>
<property name="property"><value>securitySAO</value></property>
<property name="value"><ref bean="SecuritySAO" /></property>
</bean>
-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to
deliver higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|