java Spring ProxyFactoryBean注入问题
我有一个ProxyFactoryBean:
<bean id="sendSingleSmsServiceProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="sendSingleSmsServiceImpl" />
</property>
<property name="proxyInterfaces">
<value>com.test.SendSingleSmsService</value>
</property>
<property name="interceptorNames">
<value>hibernateInterceptor</value>
</property>
</bean>
我正试图将这个bean注入另一个带有@Resource注释的bean中,下面是我的代码:
@Resource
public ProxyFactoryBean sendSingleSmsServiceProxy;
但我有一个例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.test.webservice.impl.SendSingleSmsImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'sendSingleSmsServiceProxy' must be of type [org.springframework.aop.framework.ProxyFactoryBean], but was actually of type [$Proxy24]
任何帮助都将不胜感激
# 1 楼答案
这是对
ProxyFactoryBean
所做工作的错误理解。与FactoryBean
的所有实现一样,生成的bean不是FactoryBean
的类型,而是工厂生成的任何bean的类型(see Spring docs)在您的例子中,
sendSingleSmsServiceProxy
bean将是SendSingleSmsService
类型:ProxyFactoryBean
对象实际上是透明的,您看到的是它生成的任何内容