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.

MethodAnnotationsScanner is not getting configured unless there is at least one class using the annotation

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ronmamocommented, Oct 4, 2021

fixed on 0.10

1reaction
veselovcommented, Aug 4, 2021

Bump. Is it possible to make a release with this fix?

Read more comments on GitHub >

github_iconTop 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 >

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