-
Notifications
You must be signed in to change notification settings - Fork 38.5k
excludeFilters of @ComponentScan ignored since Spring Framework 5.2 #24263
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
Thanks for the sample. Debugging shows me that the exclude filter is read and added to the scanner but scan includes the class anyway. Moving to |
Indeed, sometimes the most basic things tend to be skipped when facing/solving a software issue 😊 . It's just the exclude filter that is not applied with nothing special involved affecting the behavior of the component scanning. simple-example.zip has a simple context with 1 class to scan and 1 class to exclude. Failing test starting from Spring 5.2 |
The issue seems to be in AnnotationTypeFilter#matchSelf. The Hope this helps. |
@rob-valor great detective work! I suspected indeed the new annotation API retrieval to have a regression in this area. Thanks for the updated sample. |
The solution is to ensure that your annotation is properly retained at runtime. If you declare @Retention(RetentionPolicy.RUNTIME)
public @interface DoNotScan {
} This is effectively a duplicate of #23901. See #23901 (comment) for details, specifically:
I am therefore closing this issue. |
We'll update our code then. Thanks. Apparently I didn't read the complete part of core container |
Thanks I had the same issues, adding |
Since Spring Boot 2.2.0 the
excludeFilters
of@ComponentScan
is ignored when loading the Spring Boot application context.When using a configuration class, loaded with
spring.factories
which does a@ComponentScan
for the "framework" it provides, the application context is loading configuration classes which should be excluded (added to theexcludeFilters
). In version 2.1.11 all works fine. Starting from 2.2.0 the excluded class is loaded causing the context to fail.I added a small maven project to reproduce the issue. Switch parent pom version to 2.2.0 (or later) and maven build will fail. It looks like a Spring Boot (test context?) issue. Tests using a standard Spring context are not affected (
common-framework-boot-support
module), the@SpringBootTest
tests are (application
module).spring-componentscan-issue.zip
The text was updated successfully, but these errors were encountered: