加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

glassfish – Java EE7的拦截器问题

发布时间:2020-12-15 03:05:40 所属栏目:Java 来源:网络整理
导读:我正在测试/切换到 Java EE7(Glassfish 4),我遇到的一个问题是拦截器,每当我尝试运行项目时,我都会收到以下错误. SEVERE: Exception while loading the app : CDI deployment failure:WELD-001417 Enabled interceptor class com.xxxxxx.security.SecuredInt
我正在测试/切换到 Java EE7(Glassfish 4),我遇到的一个问题是拦截器,每当我尝试运行项目时,我都会收到以下错误.

SEVERE: Exception while loading the app : CDI deployment
failure:WELD-001417 Enabled interceptor class
com.xxxxxx.security.SecuredInterceptor in
file:/home/xxxxxx/xxxxxx/target/xxxxxx/WEB-INF/beans.xml@7 is neither
annotated @Interceptor nor registered through a portable extension

我正在看CDI 1.1规范的1.3.6节,看起来没有任何改变,所以我做错了什么?

这是我正在使用的代码;

@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,ElementType.METHOD})
public @interface Secured {}
@Secured
@Interceptor
public class SecuredInterceptor implements Serializable
{
    @AroundInvoke
    public Object interceptSecured(InvocationContext ic) throws Exception
    {
        // Do Stuff
    }
}
<?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>

解决方法

来自CDI规范的第12.1节.

A bean archive which contains a beans.xml file with no version has a default bean discovery mode of all.

您的1.1版beans.xml具有bean-discovery-mode =“annotated”.将beans.xml更改为bean-discovery-mode =“all”,我的猜测是它会像从beans.xml中删除版本并使用旧命名空间一样工作,就像在CDI 1.0中一样.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读