2016-08-14 3 views
0

Eclipse에서 Jersey를 사용하여 REST 응용 프로그램을 구성했습니다.web.xml에서 경로를 구성 할 때 REST API가 404를 찾지 못했습니다.

web.xml의 경로가 /*으로 구성되어있을 때 REST 요청을 보낼 수 없지만 /rest/*으로 변경하면 404 NOT FOUND 오류가 발생합니다. 서버에 예외가 없습니다.

web.xml 파일은 같습니다

<servlet> 
    <servlet-name>Jersey Web Application</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.app.user</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Jersey Web Application</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 
<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
</welcome-file-list> 
다음

내가 자바 파일

@Path("/rest/products") 
    public class Product { 

내가 404 오류를 얻고있는 경로를 선언하는 방법입니다 때 서버 URL의/rest/products 경로에 액세스하십시오.

무엇이 누락 되었습니까?

도움을 주시면 대단히 감사하겠습니다.

답변

1

저지 웹 응용 프로그램을 /rest/*으로 매핑하면 모든 요청의 경로에 /rest이 있어야합니다. Product 클래스를 /rest/products으로 매핑 했으므로 전체 URL은 http://localhost:port/contextRoot/rest/rest/products이어야합니다. URL에 두 번 휴식을 원하지 않으면 Product 클래스를 /products에 매핑하면됩니다.

0

당신은 에 서블릿을 매핑 한 "/ 휴식/*" URL 즉 ......./나머지는/* 서블릿 ServletContainer가 그것을 처리하기 위해 호출됩니다의 URL로 요청이있을 때마다.

@Path ("/ rest/products")이 언급되어 있습니다.

@Path에 언급 된 경로의 슬래시 때문에 404 오류가 발생합니다. 슬래시로 시작하는 경로를 지정하면 상대 경로가 아닌 절대 경로로 사용되기 때문입니다.

그래서 최종 URL이 /MyProject를/휴식/제품처럼 끝나지 않을 것 대신에 그것을 찾을 수 없습니다 /휴식/제품처럼 보일 것입니다.

따라서 오류가 발생했습니다.

관련 문제