No ServiceLocatorGenerator installed Error while Running Tests in Dropwizard
Asked Answered
C

2

8

I have upgraded Dropwizard in my project and facing issue while running unit tests, although service start up works fine and all APIs are behaving normally, problem is coming only while running tests, here are my versions:

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

below is the error when I am running "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)
Cough answered 17/4, 2017 at 13:37 Comment(2)
github.com/dropwizard/dropwizard/issues/1772 and github.com/HubSpot/dropwizard-guice/issues/95 - Seems like some dependencies integration problem.Brasca
Actually there is a pull request pending at jersey2-guice project which should resolve the problem. See this comment: github.com/Squarespace/jersey2-guice/pull/…Brasca
C
3

Calling JerseyGuiceUtils before running tests or app can help.

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

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

Christopherchristopherso answered 31/7, 2018 at 8:28 Comment(0)
S
1

Looks like incompatible versions Hk2 version.

Please refer to

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

for more details.

Sweep answered 17/4, 2017 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.