Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ProxyFactoryBean does not work with prototype advisors/interceptors [SPR-328] #5058
There are several issues in the ProxyFactoryBean which prevent it from correctly creating beans with prototype advisors:
-Cannot create proxy when using prototype advisor when singleton=false
Essentially, at the moment the only part of a prototype ProxyFactoryBean which may be a prototype is the target bean.
When trying to use a prototype the following exception is thrown:
BeanCreationException: Error creating bean with name 'prototypeTestBeanProxySingletonTarget' defined in class path resource [proxyFactoryTests.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: TargetSource specified more than once: Specify in targetSource property or at the END of the interceptorNames list
Note that in targetSource is not actually specified more than once.
The main defect is that when the factory is initialized, it avoids loading prototype beans which appear in the interceptorNames property in order to improve performance. Instead it substitutes a null value. When this null value is later examined, it cannot be determined whether the bean was supposed to be a target or an advisor.