2016-06-21 70 views
2

我創建一個動態java項目,並添加這種依賴性:我缺少運行球衣2網站服務的是什麼?

<!-- 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(); 
    } 

} 

我跑我的服務器,我把這個網址:

http://localhost:8080/ULTestServer/test/restaurantAPI/get?id=3 

但我得到錯誤404

請問我該錯過什麼? (我總是這樣,它用來工作)

回答

1

變化

jersey-container-servlet-core 

jersey-container-servlet 

的原因是後者有required component ,允許沒有發現你的應用程序web.xml替換爲@ApplicationPath。這是servlet 3可插入性機制的一部分。

第一個依賴關係用於非servlet 3.0容器,其中使用來使用web.xml來註冊Jersey servlet。


1 - Here is the implementation