在 ProxyFactoryBean 中注入属性时顺序是否重要
我正在尝试将各个方面注入到服务中。对于这项服务,我使用经典方式创建一个代理对象。
我编写了一个类型为 (ProxyFactoryBean) 的 bean-baseProxy,其中包含所有必需建议的列表。
<bean id="baseProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames">
<list>
<value>methodInvocationAdvice</value>
</list>
</property>
</bean>
我正在为这样的服务创建一个代理:
<bean id="singproxy" parent="baseProxy">
<property name="target" ref="singtarget" />
<property name="targetClass" value="com.spring.learning.SingingService"></property>
</bean>
这不起作用,但是当我恢复这两个属性并这样写时:
<bean id="singproxy" parent="baseProxy">
<property name="targetClass" value="com.spring.learning.SingingService"></property>
<property name="target" ref="singtarget" />
</bean>
令我惊讶的是它工作正常。春天,豆子的顺序重要吗?或者它是 ProxyFactoryBean 的特殊情况? 我尝试使用 Spring 3.0,但不确定以前的版本是否存在相同的行为。
I am trying to inject the aspects in a service. For this service I am creating a proxied object using classic way.
I have written a bean- baseProxy of type (ProxyFactoryBean) which contains a list of all the required advices.
<bean id="baseProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames">
<list>
<value>methodInvocationAdvice</value>
</list>
</property>
</bean>
I am creating a proxy for the service like this :
<bean id="singproxy" parent="baseProxy">
<property name="target" ref="singtarget" />
<property name="targetClass" value="com.spring.learning.SingingService"></property>
</bean>
Which doesn't work but when I revert these two properties and write like this :
<bean id="singproxy" parent="baseProxy">
<property name="targetClass" value="com.spring.learning.SingingService"></property>
<property name="target" ref="singtarget" />
</bean>
To my surprise it works fine. In spring does it matter on the order for bean ? Or its a special case with ProxyFactoryBean?
I tried with Spring 3.0 I am not sure same behavior exists with previous versions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于
target
和targetClass
来说,它是其中之一,但不能两者兼而有之。这是相关的源代码(来自 org.springframework.aop.framework.AdvisedSupport),它是 ProxyFactoryBean 的父类:如您所见,
setTarget()
和setTargetClass()
写入同一字段,因此最后一个分配获胜。Concerning
target
andtargetClass
, It's one or the other, but not both. Here's the relevant source (from org.springframework.aop.framework.AdvisedSupport), a parent class ofProxyFactoryBean
:As you can see, both
setTarget()
andsetTargetClass()
write to the same field, so the last assignment wins.