Skip to content

CGLIB proxies should still consider @Transactional annotations on interface methods [SPR-14322] #18894

Closed
@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-14322 and commented

If an application components implements an interface whose methods carry annotations that are triggering interceptors (e.g. for transactions), enabling target class proxying will result in the interceptors for those annotations not being triggered anymore. Here's a sample:

interface SomeComponent {

  @Transactional
  void init();
}

@Component
class SomeComponentImpl  implements SomeComponent {

  @Override
  public void init() {
    if (!TransactionSynchronizationManager.isActualTransactionActive()) {
      throw new IllegalStateException("Expected transaction to be active!");
    }
  }
}

@Component
class Invoker {

  public Invoker(List<SomeComponent> components) {
    components.forEach(SomeComponent::init);
  }
}

If the above is bootstrapped with standard @EnableTransactionManagement the instances handed to the constructor of Invoker are JDK proxies and the lookup of the advice chain results in the interceptor for transactions being returned and thus activated. If proxyTargetClass is set to true, the instances received by the constructor are CGLib proxies and the lookup of the advice chain results in an empty one and thus no transaction is created in the first place.


Affects: 4.2.6, 4.3 RC2

Attachments:

Issue Links:

1 votes, 9 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions