MethodAnnotationsScanner is not getting configured unless there is at least one class using the annotation
See original GitHub issueI am using reflections:0.9.12 and I want to scan for Constructors which have some annotation, let’s say @Autowired
.
public class UserService {
private UserRepository repository;
public UserService() {
}
@Autowired
public UserService(UserRepository repository) {
this.repository = repository;
}
}
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("com.sivalabs.myapp"))
.setScanners(new MethodAnnotationsScanner()));
Set<Constructor> constructorsAnnotatedWith = reflections.getConstructorsAnnotatedWith(Autowired.class);
This code is working fine if there is at least one class using @Autowired
annotation. But if there is no class using @Autowired
annotation in the package com.sivalabs.myapp
then following exception is being thrown:
Exception in thread "main" org.reflections.ReflectionsException: Scanner MethodAnnotationsScanner was not configured
at org.reflections.Store.get(Store.java:39)
at org.reflections.Store.get(Store.java:61)
at org.reflections.Store.get(Store.java:46)
at org.reflections.Reflections.getConstructorsAnnotatedWith(Reflections.java:515)
Expectation: MethodAnnotationsScanner
should be registered even when there are no classes using any particular annotation and when reflections.getConstructorsAnnotatedWith()
is called it should return empty result.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Scanner TypeAnnotationsScanner was not configured, when ...
Reflections to get annotations in classes in the class path. When i use it in the same project everything works fine, but when...
Read more >A Guide to the Reflections Library - Baeldung
Learn how to configure the Reflections library and use it in your Java ... use the MethodAnnotationsScanner to get all the methods annotated...
Read more >MethodAnnotationsScanner (Reflections 0.10.2 API) - javadoc.io
@Deprecated public class MethodAnnotationsScanner extends Object. scan method annotations. breaking change: does not include constructor annotations, use ...
Read more >Filtering based on annotations - Revapi
If no include filter is specified, all elements are included, otherwise only the elements annotated with one of the included annotations are API...
Read more >org.reflections.scanners.MethodAnnotationsScanner Java ...
The following examples show how to use org.reflections.scanners. ... Example #1 ... getAnnotation(DataScope.class); if (dataScopeAnnotation != null) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
fixed on 0.10
Bump. Is it possible to make a release with this fix?