-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Spring does not find all @ComponentScan
or @PropertySource
annotations
#30941
Comments
Thanks for the report. This looks like a bug to me, and I think Edit: however doing so does not manage overrides so I am not sure if that's such a good idea. @jhoeller, thoughts? |
@ComponentScan
not picked when present on multiple composed annotations on the same class
Right. We cannot switch to However, we might be able to introduce a variant of If I recall correctly, that restriction was included in order to match the behavior when using the Of course, simply removing |
I've pushed a "proof of concept" solution to the following feature branch. main...sbrannen:spring-framework:issues/gh-30941-repeatable-composed-ComponentScan-annotations It introduces two In addition, the rest of the test suite passes; however, if we decide to introduce these methods we will of course need to introduce additional tests. |
@ComponentScan
not picked when present on multiple composed annotations on the same class@ComponentScan
not picked when present on multiple composed annotations
We need to keep in mind that If we make the changes I proposed above, the following Javadoc for
|
@ComponentScan
not picked when present on multiple composed annotations@ComponentScan
or @PropertySource
composed annotation is discovered
In light of that, I've updated the title of this issue and pushed related tests to the aforementioned feature branch. |
@ComponentScan
or @PropertySource
composed annotation is discovered@ComponentScan
or @PropertySource
annotations
After further analysis, it turns out that in addition to not finding multiple composed Both of these bugs stem from the fact that In light of that, I have revised the title of this issue and opened #31041 to introduce explicit support for finding all repeatable annotations via the |
This is a "proof of concept". See spring-projectsgh-30941
AnnotatedTypeMetadata has various methods for finding annotations; however, prior to this commit it did not provide explicit support for repeatable annotations. Although it is possible to craft a search "query" for repeatable annotations using the MergedAnnotations API via getAnnotations(), that requires intimate knowledge of the MergedAnnotations API as well as the structure of repeatable annotations. Furthermore, the bugs reported in gh-30941 result from the fact that AnnotationConfigUtils attempts to use the existing functionality in AnnotatedTypeMetadata to find repeatable annotations without success. This commit introduces a getMergedRepeatableAnnotationAttributes() method in AnnotatedTypeMetadata that provides dedicated support for finding merged repeatable annotation attributes with full @AliasFor semantics. Closes gh-31041
Thanks very much for taking the time to fix this issue. |
You're welcome! |
Work performed in conjunction with gh-30941 resulted in a regression. Specifically, prior to Spring Framework 6.1 a locally declared @ComponentScan annotation took precedence over @ComponentScan meta-annotations, which allowed "local" configuration to override "meta-present" configuration. This commit modifies the @ComponentScan search algorithm so that locally declared @ComponentScan annotations are once again favored over @ComponentScan meta-annotations (and, indirectly, composed annotations). See gh-30941 Closes gh-31704
Affects: 6.0.11
When I compose my own annotations which all use
@ComponentScan
and I use those annotations on an application class, only the first one is used:The text was updated successfully, but these errors were encountered: