Description
Stefan Ocke opened SPR-8877 and commented
The current behavior of DefaultAopProxyFactory is to use dynamic proxy if the target has any interface other than SpringProxy. Only if the class has no interface, CGLIB is used.
When using Cobertura to measure code coverage, some instrumentation is applied to the beans. Especially, a marker interface is introduced.
This changes the behavior of Spring AOP in the way, that in places, where CGLIB was used before, dynamic proxy is used. The results are injection errors, since the proxy is not of appropriate type (... the type of the target class is required).
Looking for solutions, I found the following suggestions:
- set proxy-target-class to true or
- always use interfaces
However, in exisiting large projects, both of these solutions might imply a lot of changes and thus might not be applicable.
It would help, if there was a way to configure DefaultAopProxyFactory to not only ignore SpringProxy but also other interfaces (f.e. Cobertura marker interfaces) when making its CGLIB / dynamic proxy decision.
Currently, there is no easy way to to this. While it ist possible to configure the AopProxyFactory to be used in a ProxyFactory(Bean), there are many places in Spring code, where ProxyFactory is created by new() operator and there is no chance to set the AopProxyFactory.
Thus I would suggest
- either a System Property to configure the interfaces to be ignored by DefaultAopProxyFactory
- or a way to set a custom AopProxyFactory "globally" in the application context.
Issue Links:
- Add support for mixed, fine-grained JDK- and CGLIB-based proxying [SPR-3665] #8346 Add support for mixed, fine-grained JDK- and CGLIB-based proxying