-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide a mechanism for composed annotations to signal that they want to override attributes [SPR-13448] #18028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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: public class SomethingRegistrar implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
BeanDefinitionRegistry registry) {
AnnotationAttributes attrs = AnnotatedElementUtils.getMergedAnnotationAttributes(
ClassUtils.resolveClassName(metadata.getClassName(), null),
EnableSomething.class);
for (Class<?> type : collectClasses(attrs.get("value"))) {
BeanDefinition beanDefinition = new RootBeanDefinition(type);
registry.registerBeanDefinition("something", beanDefinition);
}
} N.B. the custom annotation has to use |
Sam Brannen commented I'm glad you found a work-around for the time being. FYI: please note that This subtlety may not have any impact on your particular use case, but... The reason I mention this difference is that 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 |
Bulk closing outdated, unresolved issues. Please, reopen if still relevant. |
Dave Syer opened SPR-13448 and commented
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 anImportBeanDefinitionRegistrar
where the annotation was a custom one and theAnnotationMetadata
that is passed in does not contain the overridden/inherited values.The reason, it turns out, is that
StandardAnnotationMetadata
, while it usesAnnotatedElementUtils
, explicitly chooses not to get the overridden attributes by invokinggetAllAnnotationAttributes()
instead ofgetMergedAnnotationAttributes()
(and this is all that is directly available to theImportBeanDefinitionRegistrar
).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).See also: #18020
Affects: 4.2 GA
Issue Links:
@AliasFor
is needed on all attributes (even if they have the same name as the "parent")@ResponseStatus
as a merged composed annotation0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: