-
Notifications
You must be signed in to change notification settings - Fork 38k
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
Explicit attribute overrides configured via @AliasFor not supported for components picked up via component scanning #23402
Comments
Thanks for raising the issue. In your example, it turns out that In contrast, when the concrete implementation type is So that at least explains what it is going on. I don't yet have a workaround or solution to your problem, but we will continue to investigate. |
@brucelwl, one way to circumvent the issue is to force the loading of If you're OK with eagerly forcing the loading of such classes, the following should work for you in Basically, the goal in the following code is to:
Class<?> clazz = null;
try {
String className = importingClassMetadata.getClassName();
clazz = ClassUtils.forName(className, null);
}
catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
EnableGitVersionControlConfig anno =
AnnotatedElementUtils.findMergedAnnotation(clazz, EnableGitVersionControlConfig.class);
logger.info("*** serverAddress={}", anno.serverAddress());
logger.info("*** targetBranch={}", anno.targetBranch()); When I execute your tests with the above change, I see the expected log output. Please let me know if this workaround works for you! Thanks, Sam |
@sbrannen Thank you very much for your reply. Your solution can solve my problem. I have another similar solution. public class GitConfigBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
private static final Logger logger = LoggerFactory.getLogger(GitConfigBeanDefinitionRegistrar.class);
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
String className = importingClassMetadata.getClassName();
Class<?> aClass = null;
try {
aClass = ClassUtils.forName(className, null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(aClass, true);
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(
metadata.getAnnotationAttributes(EnableGitVersionControlConfig.class.getName()));
logger.info("serverAddress={}", annotationAttributes.getString("serverAddress"));
logger.info("targetBranch={}", annotationAttributes.getString("targetBranch"));
}
} |
@brucelwl, thank you for the confirmation! I am glad to know that works for you. FWIW, the behavior you described is a known deficiency. Fortunately, @philwebb resolved this issue for the upcoming Spring Framework 5.2 release. This was achieved by the introduction of a new I have therefore changed the title of this issue to reflect the known deficiency, and I've assigned this issue to 5.2 so that others know that this has been addressed. Thanks again, @philwebb, for |
I have a longer set of annotation attributes, so I use
@AliasFor
to set up a short annotation. If the new annotation is set on the boot class, the value of the annotation attributes can be obtained, but the value of the annotation attributes can not be obtained on the non-boot classMaybe if you look at my demo, you can get a clearer understanding of what I mean.
https://github.com/brucelwl/demo
The text was updated successfully, but these errors were encountered: