I have always been a little irked when I saw two bean definitions:
- The target: This is the real service that will do things
- The proxy: This holds interceptors and such, and then finally delegates to the target
A usual Spring convention is to have fooTarget and foo. You know not to lookup *Target beans.
However, I want to stop people :) I don’t want it as an option.
Well, while talking about this with Rod Johnson, he told me that he had implemented this while sitting at an AOP talk at a BeJUG meeting :)
So now we can use inner bean classes:
<bean id=”person”
class=”org.springframework.aop.framework.ProxyFactoryBean”>
<property name=”proxyInterfaces”><value>com.mycompany.Person</value></property><!– Use inner bean, not local reference to target –>
<property name=”target”>
<bean class=”com.mycompany.PersonImpl”>
<property name=”name”><value>Tony</value></property>
<property name=”age”><value>51</value></property>
</bean>
</property><property name=”interceptorNames”>
<list>
<value>myAdvisor</value>
<value>debugInterceptor</value>
</list>
</property>
</bean>
Compare that to the old way:
<bean id=”personTarget” class=”com.mycompany.PersonImpl”>
<property name=”name”><value>Tony</value></property>
<property name=”age”><value>51</value></property>
</bean><bean id=”person”
class=”org.springframework.aop.framework.ProxyFactoryBean”>
<property name=”proxyInterfaces”><value>com.mycompany.Person</value></property><property name=”target”><ref local=”personTarget”/></property>
<property name=”interceptorNames”>
<list>
<value>myAdvisor</value>
<value>debugInterceptor</value>
</list>
</property>
</bean>
Obviously, I omitted the interceptor declarations
Thanks Rod, Juergen, and co!
July 28th, 2004 at 5:48 pm
Thanks Seth, I will look into the BeanNameAutoProxyCreator!
Cheers,
Dion
July 29th, 2004 at 7:24 am
This isn’t actually a new feature: it’s a combination of existing features (inner beans an ProxyFactoryBean). I just realised it was possible at the AOP seminar. So it should work in any 1.0.x release.
One major benefit of getting rid of the two definitions is that it allows the use of autowiring.
Rgds
Rod
July 20th, 2007 at 3:17 pm
every man has a fool in his sleeve
July 28th, 2007 at 10:01 am
beware of a quite dog and still water