更新到v2.27后,Jersey HK2依赖项注入无法正常工作 [英] Jersey HK2 Dependency Injection doesn't work after update to v2.27

查看:572
本文介绍了更新到v2.27后,Jersey HK2依赖项注入无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Jersey v2.25.1的项目.我使用Jersey的内置HK2注入执行依赖项注入,并且一切正常.快进到现在,我决定更新到Jersey v2.27.

I have a project using Jersey v2.25.1. I was using Jersey's inbuilt HK2 injection to perform dependency injection, and everything worked fine. Fast forward to now, I decided to update to Jersey v2.27.

运行项目时,出现以下异常:

When I ran my project, I got the following exception:

java.lang.IllegalStateException: InjectionManagerFactory not found

在进行一些谷歌搜索之后,我发现我需要添加jersey-hk2依赖项.这样做使我得到以下异常:

After some googling, I found that I needed to add the jersey-hk2 dependency. Doing so made me get the following exception:

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=<MyClass>,parent=<MyClass>,qualifiers={},position=0,optional=false,self=false,unqualified=null,1044705957)

将我所有的依赖关系还原到Jersey v2.25.1后,一切正常.我该怎么做才能解决这些错误,以便可以使用Jersey v2.27?

Upon reverting all my dependencies to Jersey v2.25.1, everything works fine. What do I need to do to fix these errors, so I can use Jersey v2.27?

我不使用Maven,所以我不能真正发布pom.xml,但是明天我将把MVCE与我所拥有的确切依赖关系以及一个依赖注入的基本示例放在一起.

I don't use Maven so I can't really post a pom.xml, but tommorow I will put together an MVCE with the exact dependencies I have, and a basic example of Dependency Injection.

推荐答案

Paul Samsotha 的答复:

尝试更改您的AbstractBinder导入.有两种,分别是球衣1和HK2.尝试使用球衣1.

Try to change your AbstractBinder import. There are two, a Jersey one and an HK2 one. Try to use the Jersey one.

基本上,我需要更改从中实现的AbstractBinder类

Basically, I needed to change the AbstractBinder class I implemented from

org.glassfish.hk2.utilities.binding.AbstractBinder

org.glassfish.jersey.internal.inject.AbstractBinder

区别在于Jersey在版本2.26中将HK2与其内部DI机制解耦,因此,我需要使用新的AbstractBinder导入,该导入直接来自Jersey,而不是HK2.

The difference is that Jersey decoupled HK2 from it's internal DI mechanism in version 2.26, and thus, I needed to use the new AbstractBinder import, which comes directly from Jersey, and not HK2.

API之间存在一些差异:例如,bindFactory()代替了Factory<T>,而使用了java.util.function.Supplier<T>.

There are a few API differences: for instance, instead of a Factory<T>, bindFactory() takes a java.util.function.Supplier<T>.

这篇关于更新到v2.27后,Jersey HK2依赖项注入无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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