Я пытаюсь добавить модульное тестирование вызовов ReST с использованием фреймворка JerseyTest в моем проекте. Я копия вставили самый простой пример, но я получаю исключение времени выполнения:Не удается запустить простой пример теста JerseyTest
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
\t at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:298)
\t at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:272)
\t at org.glassfish.jersey.test.JerseyTest.<init>(JerseyTest.java:142)
\t at com.dfc.warroom.rest.SimpleTest.<init>(SimpleTest.java:19)
\t at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
\t at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
\t at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
\t at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
\t at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
\t at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
\t at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
\t at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
\t at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
\t at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
\t at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
\t at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
\t at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
\t at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
\t at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
\t at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
\t at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
\t at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
\t at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
\t at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
\t at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
\t at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
\t at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Прикрепление кода и POM зависимостей:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import static junit.framework.Assert.assertEquals;
public class SimpleTest extends JerseyTest {
@Path("hello")
public static class HelloResource {
@GET
public String getHello() {
return "Hello World!";
}
}
@Override
protected Application configure() {
return new ResourceConfig(HelloResource.class);
}
@Test
public void test() {
final String hello = target("hello").request().get(String.class);
assertEquals("Hello World!", hello);
}
}
<dependencies>
<dependency>
<groupId>com.dfc</groupId>
<artifactId>war-room</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.6</version>
</dependency>
<!-- Required only when you are using JAX-RS Client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.3.0</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.eclipsesource.jaxrs</groupId>
<artifactId>jersey-all</artifactId>
<version>2.8</version>
</dependency>
</dependencies>
Избавьтесь от 'jersey-server' и' jersey-all' и посмотрим, что произойдет. Кажется, вы смешиваете множество зависимостей версий. NoSuchMethodError - общий результат этого. Не пробовал, но я думаю, что в этом проблема. –
Я удалил jersey-server и jersey-all, изменив версию зависимости от jersey, чтобы быть последним (2.15). Теперь я получаю новое исключение: 'java.lang.NoClassDefFoundError: org/eclipse/jetty/server/HttpConfiguration $ Customizer ' \t хотя я добавил зависимости Jetty:' org.eclipse.jetty пристань-сервер 9.3.0.M1 ' –