Description
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 implementing ResourceLoaderAware, EnvironmentAware, ImportBeanDefinitionRegistrar
which includes an snippet like this one:
ClassPathScanningCandidateComponentProvider scanner = getScanner();
AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter(HappyAnnotation.class);
scanner.addIncludeFilter(annotationTypeFilter);
scanner.setResourceLoader(this.resourceLoader);
Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents("com");
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 the candidateComponents
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.- The former implementation for
SimpleMetadataReader
made use of a visitor calledAnnotationMetadataReadingVisitor
. It has been deprecated andSimpleAnnotationMetadataReadingVisitor
is being used instead. - The new implementation of
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. - I have seen that
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