trying to scan for return type objects that are annoated with a custom annoation but the ClassPathScanningCandidateComponentProvider does not find them even though package is correct and metadata shows the methods annoated with them.
I've added a filter to my existing ClassPathScanningCandidateComponentProvider to include return types on methods annotated with a custom annoation, i.e.
@Procedure(name="PROC_MAPPING_NAME")
@CursorList(cursorType=CursorObject.class)CursorHolder<CursorObject> getCursor(@Param("col_1") @NonNull String param);
Filter is added like so
ClassPathScanningCandidateComponentProvider scanner =
new ClassPathScanningCandidateComponentProvider(false);
//existing filters
....
//new filter
scanner.addIncludeFilter(new AnnotationTypeFilter(CursorList.class));
//scan packages
return Arrays.stream(packages)
.map(scanner::findCandidateComponents)
.flatMap(Collection::stream)
.map(BeanDefinition::getBeanClassName)
.map(name -> {
try {
return Class.forName(name);
}
catch (ClassNotFoundException e) {
//handle exception
}
}).collect(Collectors.toList());
Works fine for all the existing filters and the package where the new annotation is used is definitely included as I've stepped into the code. It just fails to meet the criteria required to be considered a match and returned.
I've also tested this annotation at class level and it is then found without issue. But, it does not seem to work at attribute level or method or param level.
So stupid question given the class name. Is the ClassPathScanningCandidateComponentProvider only suitable for scanning for annoation usage when the annotation is included at class level? i.e. only finds annoated components?
If that is the case has anyone any suggestions for finding annotations and the objects they annoate where the object is a return type? Or is this just not possible?
Thanks