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
@AliasFor is needed on all attributes (even if they have the same name as the "parent") [SPR-13554] #18130
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply
From a comment in #18028. "The custom annotation has to use @AliasFor on all its inherited attributes for this to work." (And Sam said: "Are you saying that convention-based attribute overrides do not work? If so, then that's a bug, and please report it.")
Ahhhh, well... this is not a bug. Rather, this is a known limitation of convention-based attribute overrides: the value attribute is not supported as an attribute override "by convention". value can only be used as an attribute override in conjunction with @AliasFor.
The following snippet from AnnotatedElementUtils displays the logic in question.
// Implicit annotation attribute override based on conventionelseif (!AnnotationUtils.VALUE.equals(attributeName) && attributes.containsKey(attributeName)) {
overrideAttribute(element, annotation, attributes, attributeName, attributeName);
}
One of the primary reasons for this is the fact that component stereotypes (e.g., @Service, @Controller, @MyTransactionalService, etc.) declare the name of the component via the value attribute. This convention has existed since Spring 2.5, so we cannot change this.
The aforementioned @HalfConventionBasedAndHalfAliasedComposedContextConfig attempts to use a hybrid approach for attribute overrides with one attribute overriding via name-based convention and the other overriding explicitly via @AliasFor.
Since Spring does not support such a hybrid approach for annotation attribute overrides with transitive implicit aliases, I am resolving this issue as Works as Designed.
Rationale: the main problem with convention based overrides is that they are ambiguous: it is unclear for which meta-annotation the override is intended and therefore impossible to know upfront if convention-based attribute overrides should be considered as transitive implicit aliases for other local attributes. These issues can only be reliably addressed by explicit use of @AliasFor.
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply
Activity
spring-projects-issues commentedon Oct 8, 2015
Sam Brannen commented
Dave Syer, thanks for raising the issue.
I'll look into it.
If you could provide a small example that reproduces the issue (or at least sketch out the failing scenario), that would be very helpful.
Cheers,
Sam
spring-projects-issues commentedon Oct 9, 2015
Sam Brannen commented
In the interim, without further input, I have done my best to recreate the scenario that (I believe) you are describing.
Specifically, in the following
@HalfConventionBasedAndHalfAliasedComposedContextConfigannotation, we have the following attributes:locations: overrideslocationsin@ContextConfigfollowing the naming convention-based approach available prior to Spring 4.2.xmlConfigFiles: overrideslocationsin@ContextConfigusing an explicit alias declared via@AliasFor.Dave Syer, can you please confirm that the test introduced in GitHub commit 5e1d6e4 reflects the scenario you encountered?
Thanks!
Sam
spring-projects-issues commentedon Oct 12, 2015
Dave Syer commented
Yes, that looks similar at least (you are talking about
HalfConventionBasedAndHalfAliasedComposedContextConfigClassV2in your test?). The original source of this issue was this: https://github.com/spring-cloud/spring-cloud-cli/blob/master/spring-cloud-cli/src/main/java/org/springframework/boot/groovy/cloud/EnableBinding.java (I had to add@AliasForto the value attribute even though I expected it to be inherited by convention).spring-projects-issues commentedon Mar 30, 2016
Sam Brannen commented
Dave Syer,
Ahhhh, well... this is not a bug. Rather, this is a known limitation of convention-based attribute overrides: the
valueattribute is not supported as an attribute override "by convention".valuecan only be used as an attribute override in conjunction with@AliasFor.The following snippet from
AnnotatedElementUtilsdisplays the logic in question.One of the primary reasons for this is the fact that component stereotypes (e.g.,
@Service,@Controller,@MyTransactionalService, etc.) declare the name of the component via thevalueattribute. This convention has existed since Spring 2.5, so we cannot change this.spring-projects-issues commentedon Mar 31, 2016
Sam Brannen commented
The aforementioned
@HalfConventionBasedAndHalfAliasedComposedContextConfigattempts to use a hybrid approach for attribute overrides with one attribute overriding via name-based convention and the other overriding explicitly via@AliasFor.Since Spring does not support such a hybrid approach for annotation attribute overrides with transitive implicit aliases, I am resolving this issue as Works as Designed.
Rationale: the main problem with convention based overrides is that they are ambiguous: it is unclear for which meta-annotation the override is intended and therefore impossible to know upfront if convention-based attribute overrides should be considered as transitive implicit aliases for other local attributes. These issues can only be reliably addressed by explicit use of
@AliasFor.