2017-03-03 13 views
2

で404エラーを返します。 IntelliJは、私のアプリケーションが正常にデプロイされ、index.jspファイルにアクセスできると言います。Serverは常に、私はMavenを使用して</strong>のTomcat 6 <strong>ジャージー2</strong>と<strong>で実行されているシンプルなREST-サービスを取得しようとしているジャージー2 + Tomcatの6

http://localhost:8080/rest/hello

のweb.xml:

<servlet> 
    <description>JAX-RS Tools Generated - Do not modify</description> 
    <servlet-name>JAX-RS Servlet</servlet-name> 
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
    <init-param> 
     <param-name>jersey.config.server.provider.packages</param-name> 
     <param-value>com.tutorial.example</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>JAX-RS Servlet</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

のpom.xml:

私の残りのエンドポイントに移動しようとすると、私はいつも404エラーメッセージが表示されます
<groupId>com.tutorial.example</groupId> 
<artifactId>HelloWorld</artifactId> 
<version>1.0-SNAPSHOT</version> 


<dependencies> 
    <dependency> 
     <groupId>org.glassfish.jersey.containers</groupId> 
     <artifactId>jersey-container-servlet</artifactId> 
     <version>2.10.1</version> 
    </dependency> 
</dependencies> 

HelloWorld.java:

package com.tutorial; 

import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 

@Path("/hello") 
public class HelloWorld { 

    /** 
    * Method handling HTTP GET requests. The returned object will be sent 
    * to the client as "text/plain" media type. 
    * 
    * @return String that will be returned as a text/plain response. 
    */ 
    @GET 
    @Produces(MediaType.TEXT_PLAIN) 
    public String getIt() { 
     return "Got it!"; 
    } 
} 

enter image description here

は私のURLに何か問題はありますか? Tomcatログにエラーはありません。

UPDATE:それはかつて働いていた私は、私のpom.xmlに<packaging>war</packaging>を追加し、RESTエンドポイントを経由して "http://localhost:8080/rest/hello" をアクセス

答えて

2

<param-value>com.tutorial.example</param-value>

あなたのクラスはcom.tutorial.exampleパッケージではありません。 com.tutorialパッケージに入っています。ジャージーはあなたがそこに置いたクラスをスキャンして登録します。あなたのケースでは、クラスが選ばれますか?それに応じて変更を加えます。

あなたが入れたパッケージは再帰的にスキャンされることに注意してください。また、カンマで区切って複数のパッケージを置くこともできます。

+0

web.xmlに変更を加えましたが、まだ404が表示されますが、それ以外の原因は何ですか? – CodingKobold

+0

1つの可能性として、あなたのjarファイルがサーバーに追加されていない可能性があります。 ' war'をpom.xmlファイルに追加してみてください。 –

+0

それは、ありがとう! – CodingKobold

関連する問題

 関連する問題