Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring ProxyFactoryBean Injection Problem

I have a ProxyFactoryBean bean :

<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>

and I'm trying to inject this bean into another one with @Resource annotation here is my code for that :

@Resource
public ProxyFactoryBean sendSingleSmsServiceProxy;

but I get this exception :

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]

any help would be appreciated.

like image 392
aykut Avatar asked Nov 30 '25 17:11

aykut


1 Answers

This is a mis-understanding in what ProxyFactoryBean does. Like all implewntations of FactoryBean, the bean that is generated is not the type of the FactoryBean, but the type of whatever bean the factory generates (see Spring docs)

In your case, the sendSingleSmsServiceProxy bean is going to be of type SendSingleSmsService:

@Resource
public SendSingleSmsService sendSingleSmsService;

The ProxyFactoryBean object is effectively transparent, what you see is whatever it generates.

like image 153
skaffman Avatar answered Dec 02 '25 06:12

skaffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!