1
我正在尝试使用Google反射为我的自定义注释扫描类内的字段。我不知道为什么,但结果总是空的。使用Google Reflections进行注释的Java扫描类
测试类
public class AnnotationParser {
public void parse() {
String packagename = "com.security.rest.client";
final Reflections reflections = new Reflections(packagename);
Set<Field> subTypes = reflections.getFieldsAnnotatedWith(Wire.class);
for (Field field : subTypes) {
System.out.println("Class : " + field.getName());
}
}
public static void main(String[] args) {
new AnnotationParser().parse();
}
}
注解类
public class AuthenticationClient {
@Wire
public KerberosAPI kerberosAPI;
@Wire
public KerberosSessionManager kerberosSessionManager;
}
定制标注
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Wire {
}
请让我知道是否需要其他信息。