簡體   English   中英

在沒有web.xml的Jersey中出現404錯誤

[英]Getting 404 error in Jersey with no web.xml

我正在遵循Jersey教程來開發簡單的Jersey Web應用程序。

通過遵循部分- 示例2.9。 使用@ApplicationPath和Servlet 3.0部署JAX-RS應用程序

我已經創建了下面的程序:

@ApplicationPath("resources")
public class MyApplication extends PackagesResourceConfig {
    public MyApplication() {
        super("com.examples");
    }
}

我有下面的基本資源類:

@Path("/helloworld")
public class HelloWorldResource {

    @GET
    @Produces("text/plain")
    public String getClichedMessage() {
        return "Hello World";
    }
 }

我正在使用Jersey-1.19版本,我的Web應用程序中沒有任何web.xml文件。 現在,我將應用程序部署在Tomcat 7服務器上。

當我嘗試以以下方式訪問URL時: http://localhost:8080/myapp/resources/helloworld我收到以下錯誤消息:

HTTP狀態404-/ myapp / resources / helloworld類型狀態報告

訊息:/ myapp / resources / helloworld

描述:請求的資源不可用。

您需要jersey-servlet依賴項

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.19</version>
</dependency>

如果您不希望使用web.xml。 它具有加載應用程序所需的JerseyServletContainerInitializer


對於僅此一個尋找Jersey 2.x解決方案的未來讀者,您需要以下依賴項才能使用無web.xml的文件

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>${jersey2.version}</version>
</dependency>

出於相同的原因-它具有JerseyServletContainerInitializer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM