I have a custom annotation in my program that I apply to methods. I would like to find all methods with a particular annotation. From my application code, I can use the Reflections package to do so:
new Reflections(
new ConfigurationBuilder().setUrls(
ClasspathHelper.forPackage("com.my.package")
).setScanners(new MethodAnnotationsScanner())
).getMethodsAnnotatedWith(MyAnnotation.class);
However, when I try to do the same from an integration test invoked via failsafe
to find the annotated methods in the application (not in the test), no methods are found. How can I get my annotated methods from an integration test?
There were two things I had to change to get things to work:
I changed the Reflections
instantiation as follows:
new Reflections("com.my.package", new MethodAnnotationsScanner());