Skip to content

DefaultAopProxyFactory: Make configurable, which interfaces are not considered user supplied. To better support code instrumentation from tools like Cobertura. [SPR-8877] #13518

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions