Я использую Jersey 2.7 для создания остальных веб-сервисов. Вот связанный файл pom. xml:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.27</version>
</dependency>
И класс приложения:
@ApplicationPath("rest")
public class Application extends ResourceConfig {
public Application() {
this.packages("com.my.packge");
}
}
И класс api:
@Path("/api")
public class myApi {
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Path("/test")
public String test(){
return "I'm here!";
}
}
Я использую tomcat для запустите программу и вот результат:
Message The requested resource [/rest/api/test2] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.