如何在Java Jersey中使用CDI事件?

我试图关注这篇文章的upvoted答案:
Best practice for REST token-based authentication with JAX-RS and Jersey

我正在使用CDI方法,在我的过滤器中我有定义:

@Inject
@AuthenticatedUser
Event<String> userAuthenticatedEvent;

但是,当我运行tomcat 7时,我收到以下错误:

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=Event<String>,parent=AuthenticationFilter,qualifiers={@com.wink.rest.security.annotation.AuthenticatedUser()},position=-1,optional=false,self=false,unqualified=null,567185196)
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
    at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:945)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:979)
    at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanHk2Factory$2.getInstance(AbstractCdiBeanHk2Factory.java:142)
    at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanHk2Factory._provide(AbstractCdiBeanHk2Factory.java:91)
    at org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanHk2Factory.provide(GenericCdiBeanHk2Factory.java:63)

我已尝试在google和stackoverflow上找到的所有内容尝试解决此问题,但没有一个解决方案有效.所以现在我不确定还能做什么.有人有什么建议吗?

最佳答案 在努力解决同样的问题之后,我找到了解决方法.我从TomCat切换到Glassfish并更新maven依赖项以匹配
official Jersey 2 documentation中的那些.之后它就像魔术一样工作.

点赞