我正在测试/切换到Java EE7(Glassfish 4),我遇到的一个问题是拦截器,每当我尝试运行项目时,我都会收到以下错误.
严重:加载应用程序时出现异常:CDI部署失败:WELD-001417文件中启用拦截器类com.xxxxxx.security.SecuredInterceptor:/home/xxxxxx/xxxxxx/target/xxxxxx/WEB-INF/beans.xml@7既不是注释@Interceptor也没有通过便携式扩展注册
我正在看CDI 1.1规范的1.3.6节,它看起来没什么变化,所以我做错了什么?
这是我正在使用的代码;
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Secured {}
Run Code Online (Sandbox Code Playgroud)
@Secured
@Interceptor
public class SecuredInterceptor implements Serializable
{
@AroundInvoke
public Object interceptSecured(InvocationContext ic) throws Exception
{
// Do Stuff
}
}
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
<interceptors>
<class>com.xxxxxx.security.SecuredInterceptor</class>
</interceptors>
</beans>
Run Code Online (Sandbox Code Playgroud)