自定义注释处理器未被tomcat调用。以下是我正在使用的注释处理器代码:自定义注释处理器未被tomcat调用
@SuppressWarnings("restriction")
@SupportedAnnotationTypes("io.strati.rs.cxf2.bindings.MyAnnotation")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class SimpleAnnotationProcessor extends AbstractProcessor {
public static List<String> str = new ArrayList<>();
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
System.out.println("Into annotation processor ... 2");
for (Element element : roundEnv.getElementsAnnotatedWith(MyAnnotation.class)) {
System.out.println("Method name is:"+element.getSimpleName());
str.add(element.getSimpleName().toString());
}
return false;
}
}
这存储了所有具有自定义注释的方法的名称。这是注记类的样子:
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(value = RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
}
我试图访问一个Tomcat应用程序列表如下:
@GET
@Path("/dummy")
@MyAnnotation
@Produces({APPLICATION_JSON, APPLICATION_XML, TEXT_XML})
public void print(){
System.out.println("List is:"+SimpleAnnotationProcessor.str);
}
名单越来越打印为空,即使该方法具有我已经在maven编译器插件中指定了注释,并在META-INF/services/javax.annotation.processing.Processor中指定了它。有人能告诉我什么是可能的原因,因为注释处理器没有被调用?