我已经在我的项目中升级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)
答案 0 :(得分:1)
在运行测试或应用程序之前调用JerseyGuiceUtils会有所帮助。
static {
JerseyGuiceUtils.install((s, serviceLocator) -> null);
}
答案 1 :(得分:0)