我有一个AOP代理bean,定义如下:
<bean id="someService" class="..FactoryBean">
..
<property name="target">
<ref local="target" />
</property>
<property name="preInterceptors"><ref local="serviceInterceptors"/></property>
..
</bean>
目标bean:
<bean id="target" class=".." />
和目标bean的孩子:
<bean parent="target">
<!-- set some properties -->
</bean>
我想将目标bean更改为匿名bean,但要维护子bean。唯一的问题是将子bean的 parent 属性设置为AOP代理bean继承自工厂bean而不是目标bean。有解决方法吗?
答案 0 :(得分:1)
不漂亮,但应该有效:
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="com.foo.bar.ExampleService" />
</property>
</bean>
<bean id="targetSource" factory-bean="proxy" factory-method="getTargetSource" />
<bean id="parent" factory-bean="targetSource" factory-method="getTarget" />
<bean parent="parent" />