在 Dropwizard 中运行测试时没有安装 ServiceLocatorGenerator 错误

use*_*324 8 jersey guice dropwizard hk2

我已经在我的项目中升级了 Dropwizard 并在运行单元测试时遇到了问题,虽然服务启动工作正常并且所有 API 都运行正常,但只有在运行测试时才会出现问题,这是我的版本:

Dropwizard: 1.1.0
Jersey: 2.25.1
Guice: 4.1.0
hk2-api: 2.5.0-b36
hk2-utils: 2.5.0-b36
javax.ws.rs-api : 2.1-m05
Run Code Online (Sandbox Code Playgroud)

以下是我运行“mvn test”时的错误

java.lang.RuntimeException: java.lang.ClassNotFoundException: Provider org.glassfish.jersey.internal.RuntimeDelegateImpl could not be instantiated: java.lang.IllegalStateException: It appears there is no ServiceLocatorGenerator installed.
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:153)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:121)
at javax.ws.rs.core.Response$ResponseBuilder.newInstance(Response.java:848)
at javax.ws.rs.core.Response.status(Response.java:590)
at javax.ws.rs.core.Response.status(Response.java:601)
at javax.ws.rs.core.Response.ok(Response.java:622)
...... ** some more lines here **
Caused by: java.lang.ClassNotFoundException: Provider org.glassfish.jersey.internal.RuntimeDelegateImpl could not be instantiated: java.lang.IllegalStateException: It appears there is no ServiceLocatorGenerator installed.
at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:123)
at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:226)
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:137)
Run Code Online (Sandbox Code Playgroud)

小智 1

看起来像是不兼容版本 HK2 版本。

请参阅

https://github.com/dropwizard/dropwizard/issues/1772

更多细节。