2

Google リフレクションを使用して、カスタム アノテーションのクラス内のフィールドをスキャンしようとしています。理由はわかりませんが、結果は常に空のセットになります。

テストクラス

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 {

}

他に情報が必要な場合はお知らせください。

4

1 に答える 1