You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a mechanism for composed annotations to signal that they want to override attributes [SPR-13448] #18028
in: coreIssues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process
AnnotatedElementUtils is now available for processing merged (overridden) attributes from meta-annotated custom annotations, but Spring doesn't use it uniformly (because of performance concerns). The one that bit me was an ImportBeanDefinitionRegistrar where the annotation was a custom one and the AnnotationMetadata that is passed in does not contain the overridden/inherited values.
The reason, it turns out, is that StandardAnnotationMetadata, while it uses AnnotatedElementUtils, explicitly chooses not to get the overridden attributes by invoking getAllAnnotationAttributes() instead of getMergedAnnotationAttributes() (and this is all that is directly available to the ImportBeanDefinitionRegistrar).
Maybe there's a way to address the performance concerns and use the deeper AnnotatedElementUtils.getMergedAnnotationAttributes() utility method(s) only if the user signals that the annotation needs to be processed this way -- for example, by introducing an annotation such as @Mergeable (or an explicit @AliasFor on the attribute).
There is a workaround for my current specific issue (because I control the ImportBeanDefinitionRegistrar), which is to use the more powerful method in AnnotatedElementUtils explicitly:
I'm glad you found a work-around for the time being.
FYI: please note that getAllAnnotationAttributes() and getMergedAnnotationAttributes() actually have quite different semantics. getAllAnnotationAttributes() aggregates attributes across all annotations present above the annotated element; whereas, getMergedAnnotationAttributes() only merges attributes from a single branch in the annotation hierarchy.
This subtlety may not have any impact on your particular use case, but...
The reason I mention this difference is that getAllAnnotationAttributes() will find multiple instances of the target annotation (if present), but getMergedAnnotationAttributes() will only find one instance of the target annotation, ignoring any other instances of the target annotation that may be present. Typically, only @Profile and @Conditional require the "aggregate" semantics.
Make sense?
N.B. the custom annotation has to use @AliasFor on all its inherited attributes for this to work.
What do you mean by "all" in this context?
Are you saying that convention-based attribute overrides do not work? If so, then that's a bug, and please report it.
in: coreIssues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process
Activity
spring-projects-issues commentedon Sep 9, 2015
Dave Syer commented
There is a workaround for my current specific issue (because I control the ImportBeanDefinitionRegistrar), which is to use the more powerful method in AnnotatedElementUtils explicitly:
N.B. the custom annotation has to use
@AliasForon all its inherited attributes for this to work.spring-projects-issues commentedon Sep 10, 2015
Sam Brannen commented
Dave Syer,
I'm glad you found a work-around for the time being.
FYI: please note that
getAllAnnotationAttributes()andgetMergedAnnotationAttributes()actually have quite different semantics.getAllAnnotationAttributes()aggregates attributes across all annotations present above the annotated element; whereas,getMergedAnnotationAttributes()only merges attributes from a single branch in the annotation hierarchy.This subtlety may not have any impact on your particular use case, but...
The reason I mention this difference is that
getAllAnnotationAttributes()will find multiple instances of the target annotation (if present), butgetMergedAnnotationAttributes()will only find one instance of the target annotation, ignoring any other instances of the target annotation that may be present. Typically, only@Profileand@Conditionalrequire the "aggregate" semantics.Make sense?
What do you mean by "all" in this context?
Are you saying that convention-based attribute overrides do not work? If so, then that's a bug, and please report it.
Cheers,
Sam
spring-projects-issues commentedon Jan 12, 2019
Bulk closing outdated, unresolved issues. Please, reopen if still relevant.