Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
ProxyFactoryBean doesn't warn when it cannot determine if last interceptorNames element is or not an Advice/Advisor [SPR-4640] #9317
My configuration uses a ProxyFactoryBean to proxy another bean, that itself is a TransactionProxyFactoryBean on the final target bean.
When the application start, an exception is throwed : AopConfigException("Unknown advisor type ...
My ProxyFactoryBean configuration uses the interceptorNames to set both interceptors and the target bean. ProxyFactoryBean .checkInterceptorNames() is expected to detect the last element to be the target bean. isNamedBeanAnAdvisorOrAdvice() ask the beanFactory for the element type. In my case this doesn't resolve (maybe because the target is itself a ProxyFactoryBean ?) and the default value "true" is returned.
1 - there is no log to inform the ProxyFactoryBean took this fallback decision. Some INFO level message would have been very helpfull to find this issue.
2 - I don't understand why such a type-check is required as my configuration does not declare a target/targetSource/targetName. In such a case, the last interceptorNames element MUST be the target bean.
Maybe using interceptorNames to set the target bean is considered confusing and should be deprecated (IMHO)
nicolas de loof commented
The attached patch change the ProxyFactoryBean initialization to rely on InitializingBean.afterPropertiesSet() :
If no targetSource / targetName has been set, select the last interceptorNames element as a target, with no check for bean type. This required to make a tiny change on the testcase for testGetObjectTypeWithNoTargetOrTargetSource as the exception thrown is AopInvocationException, not UnsupportedOperationException. Can be considered a compatibile change ?
Maybe it could also check for the bean NOT to be an interceptor if the beanFactory can retrieve the bean type ?
Juergen Hoeller commented
I've opted for deprecating the target-name-as-final-element-in-"interceptorNames" feature altogether, as well as changing the detection algorithm to assume a target object (rather than an Advisor/Advice) if the type cannot be determined - which should be a more reasonable default. I've also added some further debug logging.
Juergen Hoeller commented
"afterPropertiesSet"-style checking may have subtle side effects here due to ProxyFactoryBean being supported within circular references as well. The general deprecation of this questionable feature along with the change in default assumption when the type cannot be determined should be the better tradeoff.