问题
I was using
Reflections reflections = new Reflections("com.mypackage.root", new MethodAnnotationsScanner());
But with this aproach i get back a lot of annotations in packages level that i don't need... What i really want for, is something like this, using an wildcard to get back the deep package level only.
Reflections reflections = new Reflections("com.mypackage.root.*.deep", new MethodAnnotationsScanner())
Because the methods that i really need is in ".deep" package level... I try a lot of combinations with FilterBuilder, then i don't know if i am doing something wrong or this is not possible with this API
回答1:
Try
Reflections reflections = new Reflections("com.mypackage.root", new MethodAnnotationsScanner());
Set<Method> methods = reflections
.getMethodsAnnotatedWith(MyAnnotation.class).stream()
.filter(method -> method.getDeclaringClass().getPackage().getName().matches("com.mypackage.root.*.deep"))
.collect(Collectors.toSet());
来源:https://stackoverflow.com/questions/59145550/i-can-use-org-reflection-to-get-package-classes-using-wildcard