我创建了一个动态java项目并添加了这个依赖项:
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.23.1</version>
</dependency>
然后我创建了这样的App类:
@ApplicationPath("/test")
public class App extends ResourceConfig {
public App() {
this.packages("com.test.ul");
}
}
并且在与App类相同的包中,我创建了这个:
@Path("restaurantAPI")
public class RestaurantAPI {
@Path("/get")
@GET
public Response getRequest(@PathParam("id") String id) {
return Response.ok(id).build();
}
}
我运行我的服务器,并将此URL称为:
http://localhost:8080/ULTestServer/test/restaurantAPI/get?id=3
但我收到错误404
我错过了什么? (我总是这样做,过去常常工作)
答案 0 :(得分:1)
更改
jersey-container-servlet-core
到
jersey-container-servlet
原因是后者具有required component 1 ,允许在没有web.xml的情况下发现您的应用程序,替换为@ApplicationPath
。这是servlet 3可插拔机制的一部分。
第一个依赖项用于非servlet 3.0容器,其中使用使用web.xml来注册Jersey servlet。