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

时间:2017-04-17 13:37:31

标签: 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

下面是我正在运行" 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)

2 个答案:

答案 0 :(得分:1)

在运行测试或应用程序之前调用JerseyGuiceUtils会有所帮助。

static {
    JerseyGuiceUtils.install((s, serviceLocator) -> null);
}

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

答案 1 :(得分:0)

看起来像Hk2版本不兼容的版本。

请参阅

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

了解更多详情。