什么是我缺少运行球衣2网络服务?

时间:2016-06-21 15:37:12

标签: java apache jersey jersey-2.0

我创建了一个动态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

我错过了什么? (我总是这样做,过去常常工作)

1 个答案:

答案 0 :(得分:1)

更改

jersey-container-servlet-core

jersey-container-servlet

原因是后者具有required component 1 ,允许在没有web.xml的情况下发现您的应用程序,替换为@ApplicationPath。这是servlet 3可插拔机制的一部分。

第一个依赖项用于非servlet 3.0容器,其中使用使用web.xml来注册Jersey servlet。

1 - Here is the implementation