ClassPathScanningCandidateComponentProvider behaviour not scanning annotated classes anymore (spring-context 5.1.17 -> 5.2.8) #25726
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: duplicate
A duplicate of another issue
demo-annotationtypefilter.zip
Hi, first time here. Please bear with me if this report has to be fixed somehow.
We have recently upgraded Spring Boot 2.1.16 to 2.3.3 and we have found differences in the behaviour of
ClassPathScanningCandidateComponentProvider
which are breaking something we had working.Essentially, we have a
@Configuration
class implementingResourceLoaderAware, EnvironmentAware, ImportBeanDefinitionRegistrar
which includes an snippet like this one:With this, we would be able to find interfaces in the classpath annotated with
@HappyAnnotation
, to which we would do some operation later to have them registered in the Spring context. Now thecandidateComponents
is empty, so nothing will be registered.We have noticed several things:
ClassPathScanningCandidateComponentProvider
makes use of aSimpleMetadataReader
at some point. The implementation for it has changed.SimpleMetadataReader
made use of a visitor calledAnnotationMetadataReadingVisitor
. It has been deprecated andSimpleAnnotationMetadataReadingVisitor
is being used instead.SimpleMetadataReader
ends up with an attributeannotationMetadata
of typeSimpleAnnotationMetadata
, which at the same time hasannotations
(TypeMappedAnnotations
) with anannotationFilter
being shown in debug as "All annotations filtered", which suggests all annotations are ignored.AnnotationMetadataReadingVisitor
is mentioned to be deprecated and replaced for the other one but no public replacement for it is being provided, as per documentation. I am not really sure this pattern we use is valid anymore.I attach an small project that reproduces the issue. Just change the commented spring boot parent version in the pom for the other one to reproduce.
If not a bug and if time allows, please forward me to some documentation which explains how to get our
Set<BeanDefinition>
correctly in this version.Thanks in advance,
JP
The text was updated successfully, but these errors were encountered: