question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

excludeFilters of @ComponentScan ignored since Spring Framework 5.2

See original GitHub issue

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 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-supportmodule), the @SpringBootTest tests are (application module). spring-componentscan-issue.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rob-valorcommented, Dec 26, 2019

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 😉

2reactions
rob-valorcommented, Dec 25, 2019

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 my excludeFilters marker annotation which it does not in Spring 5.1.

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ComponentScan excludeFilters Not Working In Spring 4.0.6 ...
After lot of work and research I noticed that Spring's behavior is little weird in term of component scanning. Artifacts were like this...
Read more >
Spring - Using excludeFilters attribute of @ComponentScan to ...
@ComponentScan#excludeFilters can be used to exclude component classes from scanning. ... ComponentScan; import org.springframework.context.annotation.
Read more >
ComponentScan (spring-context 5.2.8.RELEASE API)
Base packages to scan for annotated components. ComponentScan.Filter[], excludeFilters. Specifies which types are not eligible for component scanning.
Read more >
Spring @ComponentScan - Filter Types - Baeldung
We can extend this behavior by using includeFilters and excludeFilters parameters of the @ComponentScan annotation.
Read more >
org.springframework.context.annotation.ComponentScan ...
ComponentScan maven / gradle build tool code. The class is part of the package ➦ Group: org.springframework ➦ Artifact: spring-context ➦ Version: 5.2.3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found