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
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:
If the above is bootstrapped with standard
@EnableTransactionManagementthe instances handed to the constructor ofInvokerare JDK proxies and the lookup of the advice chain results in the interceptor for transactions being returned and thus activated. IfproxyTargetClassis set totrue, 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:
@Transactionaldoes not appear to work in custom repository implementation@Cacheabledeclarations on interface methods@Asyncif there is another interceptor1 votes, 9 watchers