如何在Java Jersey中使用CDI事件? [英] How to use CDI Events in Java Jersey?

查看:293
本文介绍了如何在Java Jersey中使用CDI事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循该帖子的最高评价:

I am trying to follow this post's upvoted answer: Best practice for REST token-based authentication with JAX-RS and Jersey

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

I'm using the CDI approach and in my filter i have the definition:

@Inject
@AuthenticatedUser
Event<String> userAuthenticatedEvent;

但是,当我运行tomcat 7时,出现以下错误:

But, when I run tomcat 7, I get the following error:

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上找到的所有内容来尝试解决此问题,但是没有一种解决方案有效.因此,现在我不确定该怎么办.有人有什么建议吗?

I have tried everything I found on google and stackoverflow to try to resolve this, but none of the solutions worked. So now I'm not sure what else to do. Anyone have any advice?

推荐答案

在遇到同样的问题后,我找到了解决方案.我从TomCat切换到Glassfish,并更新了Maven依赖项以匹配官方球衣的依赖项2个文档.之后,它就像魔术一样起作用.

After struggling with the same exact issue I found a solution to that. I switched from TomCat to Glassfish and updated maven dependencies to match the ones from official Jersey 2 documentation. After that it worked like magic.

这篇关于如何在Java Jersey中使用CDI事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆