Description
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:
- tx-differences.zip (54.85 kB)
Issue Links:
- DATAJPA-1222 Overriding type level
@Transactional
does not appear to work in custom repository implementation - Consider target-class proxy mode by default [SPR-14515] #19084 Consider target-class proxy mode by default
- Revisit storage of null attributes in AbstractFallbackTransaction/CacheAttributeSource [SPR-15513] #20072 Revisit storage of null attributes in AbstractFallbackTransaction/CacheAttributeSource
- Caching annotation on interface are ignored when cglib proxies are used [SPR-14343] #18915 Caching annotation on interface are ignored when cglib proxies are used
- Reliably detect @Cacheable declarations on interface methods [SPR-15271] #19836 Reliably detect
@Cacheable
declarations on interface methods - Cglib proxy not working with @Async if there is another interceptor [SPR-14949] #19516 Cglib proxy not working with
@Async
if there is another interceptor
1 votes, 9 watchers