Repository navigation
Description
Sam Brannen opened SPR-11108 and commented
Status Quo
The findAnnotation() methods in AnnotationUtils currently support searching for meta-annotations declared on composed annotations that are declared on interfaces; however, various parts of the framework -- for example, code that relies on AnnotationAttributes - only support composed annotations on classes or methods (not on interfaces or interface methods).
For example, given the following:
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(rollbackFor=Exception.class, noRollbackFor={IOException.class})
public @interface TxWithAttribute {
boolean readOnly();
}
@TxWithAttribute(readOnly = true)
public static interface TestInterface9 {
public int getAge();
}
public static class TestBean9 implements TestInterface9 {
@Override
public int getAge() {
return 10;
}
}
public static interface TestInterface10 {
@TxWithAttribute(readOnly=true)
public int getAge();
}
public static class TestBean10 implements TestInterface10 {
@Override
public int getAge() {
return 10;
}
}Spring's support for resolving transaction attributes (e.g., the AbstractFallbackTransactionAttributeSource.computeTransactionAttribute() to SpringTransactionAnnotationParser.parseTransactionAnnotation() call stack) fails to find @Transactional which is declared via @TxWithAttribute on interfaces.
Proposal
Introduce support for composable stereotype annotations declared on interfaces.
Affects: 4.0 RC1
Issue Links:
- Allow meta-annotations to override attributes from their parent [SPR-10181] #14814
- Provide meta-annotation support for test-related annotations [SPR-7827] #12483
- Support meta-annotation attribute overrides in the TestContext framework [SPR-11038] #15666
- AnnotatedElementUtils does not find annotations on methods in dynamic proxies [SPR-12703] #17300
- AnnotatedElementUtils fails to find annotations on abstract, bridge, or interface methods [SPR-12738] #17335
1 votes, 3 watchers
Activity
spring-projects-issues commentedon Nov 22, 2013
Sam Brannen commented
To reproduce this lacking support, see the
customClassAttributeWithReadOnlyOverrideOnInterface()andcustomMethodAttributeWithReadOnlyOverrideOnInterface()tests introduced inAnnotationTransactionAttributeSourceTestsfrom GitHub commit ad402dc.spring-projects-issues commentedon Nov 22, 2013
Juergen Hoeller commented
Good point. Alright, let's try to roll this into 4.0 RC2 still...
Juergen
spring-projects-issues commentedon Nov 22, 2013
Juergen Hoeller commented
Sam, this doesn't seem to have much to do with AnnotationAttributes or the like...
It's rather that we generally only detect
@Transactionalannotations on an interface if the invocation comes in through that interface. So in those unit tests, you simply need to pass in the interface method instead of the target class method (which I've just changed and committed). If that's the case, both direct lookups and meta-annotation lookups work. So with JDK proxies, all should be fine. With CGLIB proxies, neither of those two variants works - just like before. It's generally arguable whether CGLIB proxies should also check interfaces there, but anyway, it doesn't seem to be an inconsistency between direct and meta use of@Transactional.Let me know if I'm missing something...
Juergen
spring-projects-issues commentedon Feb 3, 2014
Sam Brannen commented
Juergen, just to recap on our discussion...
I mentioned support for
@Transactionalonly as an example to demonstrate the issue. The crux of the issue is described in the opening sentence:So there is in fact a difference in the behavior of
AnnotatedElementUtilsandAnnotationUtilswith regard to traversal of interfaces. Whether or not this difference poses an actual problem for end users' code at runtime will require further analysis of current use ofAnnotationAttributes,AnnotatedElementUtils, etc. across the code base.Regards,
Sam
spring-projects-issues commentedon Apr 22, 2015
Sam Brannen commented
Update: #17300 covers interface support in
AnnotatedElementUtils; however, I am leaving this issue open for the time being in order to ensure we cover the same use cases for Spring's ASM-based annotation processing support (e.g.,AnnotationAttributesReadingVisitor, etc.).sbrannen commentedon Mar 25, 2025
No issues have been reported related to this topic in almost 10 years. In addition, we have since switched to a
MergedAnnotations-based implementation for our ASM support in theorg.springframework.core.type.classreadingpackage.In light of that, I am closing this issue.