我刚在Websphere 8.5.5上启用了CDI并添加了拦截器
在beans.xml文件中
<?xml version="1.0"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemeLocation="http://java.sun.com/xml/ns/javaee http://
java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>com.example.jaxrs.SecurityChecked</class>
</interceptors>
</beans>
SecurityChecked annotation
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;
@Inherited
@InterceptorBinding
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface SecurityChecked {
}
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@Interceptor
@SecurityChecked
public class SecurityCheckInterceptor {
@AroundInvoke
public Object checkSecurity(InvocationContext context) throws Exception {
/*
* check the parameters or do a generic security check before invoking
* the original method
*/
Object[] params = context.getParameters();
/* if security validation fails, you can throw an exception */
System.out.println("in securitycheck interceptor");
/* invoke the proceed() method to call the original method */
Object ret = context.proceed();
/* perform any post method call work */
return ret;
}
}
在JAX-RS课程中如下
@GET
@com.example.jaxrs.SecurityChecked
public String checkInterceptor(String hello) {
return "Hello world!";
}
当我部署EAR时,我得到以下错误。
WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container正在启动......
[10/15/14 14:53:15:259 EDT] 00000067 BeansDeployer E BeansDeployer部署org.apache.webbeans.exception.WebBeansConfigurationException:给定类:接口com.example.jaxrs.SecurityChecked不是拦截器类< / p>
任何建议是什么原因导致此错误?
答案 0 :(得分:3)
错误消息说明了一切。 SecurityChecked
不是拦截器,只是用于拦截器绑定的注释。拦截器是SecurityCheckInterceptor
所以你的beans.xml应该包含:
<interceptors>
<class>com.example.jaxrs.SecurityCheckInterceptor</class>
</interceptors>
的问候,
Svetlin