excludeFilters of @ComponentScan ignored since Spring Framework 5.2
See original GitHub issueSince 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 the excludeFilters
). 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
We’ll update our code then. Thanks. Apparently I didn’t read the complete part of core container in Upgrading to Version 5.2. Sorry guys 😉
The issue seems to be in AnnotationTypeFilter#matchSelf. The
AnnotationMetadata
implematation is completely different (5.2:SimpleAnnotationMetadata
, 5.1:AnnotationMetadataReadingVisitor
) and apparently missing valuable class level annotation information.AnnotationMetadata#hasAnnotation
returns false when looking for myexcludeFilters
marker annotation which it does not in Spring 5.1.Hope this helps.