我正在使用Jersey 2.7创建其余的Web服务。这是相关的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.