CDI 定义 failure:WELD-001476: 拦截器 [class] 必须是 @Dependent

CDI definition failure:WELD-001476: Interceptor [class] must be @Dependent

我正在试用 APM MoSKito 并一直在尝试部署将映射到 [context]/mui/* 的嵌入式 Web UI,其中将显示 MoSKito 界面。

问题是我在部署应用程序时遇到以下错误:

CDI definition failure:WELD-001476: Interceptor [class net.anotheria.moskito.integration.cdi.CountInterceptor intercepts @Count] must be @Dependent

拦截器在beans.xml中声明:

<interceptors>
    <class>net.anotheria.moskito.integration.cdi.CountInterceptor</class>
    <class>net.anotheria.moskito.integration.cdi.CallInterceptor</class>
</interceptors>   

但是由于我无法修改此 APM 的 Maven 存储库,所以我无法真正让这些 类 使用 @Dependent 注释,所以我不太明白这个问题,我真的很感激一些帮助。谢谢!

问题是低于 2.7.0 的 MoSKito 的拦截器上有 @Singleton 注释。这没有通过 Weld 验证(拦截器必须是 @Dependent bean)并导致所描述的异常。

因此,解决方案是将框架升级到 2.7.0+。因此,需要更新 beans.xml,因为拦截器的包名也发生了变化。