此规则将标记满足以下条件的定制注释上 ElementType.TYPE 以外的 @Target 值:
- 使用
@InterceptorBinding 来注释定制注释。
- 在使用
@Interceptor 进行注释的类上使用定制注释。
- 使用定制注释进行注释的类还包含其任一方法上的至少一个生命周期拦截器注释。
以下是生命周期拦截器注释:
- javax.annotation.PostConstruct
- javax.annotation.PreDestroy
- javax.ejb.PostActivate
- javax.ejb.PrePassivate
- javax.interceptor.AroundConstruct
以下示例不符合 Java EE 7 Contexts and Dependency Injection (CDI) 1.2 规范,但在基于 Apache OpenWebBeans 实现的 CDI 1.0 实现中可被接受。在基于 Weld 实现的 CDI 1.2 中,应用程序不会启动。
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface MyIInterceptorBinding {}
@Interceptor
@MyIInterceptorBinding
public class MyIInterceptor {
@PostActivate
void postActivate (InvocationContext inv)
@PreDestroy
void preDestroy (InvocationContext inv)
}
|
要解决此问题,请从 @Target 注释中移除 ElementType.METHOD,并移除对应用程序方法上注释的所有引用。
如果指定了 ElementType.TYPE 以外的任何元素类型,那么还必须移除这些元素类型。
有关 Java EE 7 CDI 1.2 实现的更多信息,请参阅
Contexts and Dependency Injection 1.2 行为更改。