2017-02-02 2 views
1

Jersey 프레임 워크와 Netbean SDK를 사용하여 간단한 프로젝트 RESTful API를 사용하고 있습니다.RESTful Jersey 다중 리소스 및 패키지

나는 리소스를 생성하고 기본 이외의 다른 패키지에 넣어, 또한 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>trial1.jerseytutorial</param-value> 
    </init-param> 
    <init-param> 
     <param-name>jersey.config.server.provider.packages</param-name> 
     <param-value>Profile</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>Jersey Web Application</servlet-name> 
    <url-pattern>/webapi/*</url-pattern> 
</servlet-mapping> 

나는 또한에있는 자원을 정의 여기 The resource is CustomerProfile, and package is Profile. Package "Profile" is not part of the default package 내 XML입니다 CustomerProfile.java

package Profile; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 
@Path("/CustomerProfile")  // the URL path leading to the resource 
public class CustomerProfile { 
@GET   // map the method to HTTP Get 
@Produces(MediaType.TEXT_PLAIN) // tell the return format of the request 
    public String getProfile() { 
     return "Got the profile !"; 
    } 
} 

그러나 http://localhost:8080/JerseyTutorial/webapi/CustomerProfile으로 이동하면 404 오류가 발생합니다. 내 XML 서블릿이 옳지 않다고 의심된다.

<init-param> 
    <param-name>jersey.config.server.provider.packages</param-name> 
    <param-value> 
     trial1.jerseytutorial, 
     Profile 
    </param-value> 
</init-param> 

구분

답변

0

사용 쉼표 (세미콜론)는 그것을 시도하지 않은,하지만 난 (쉼표 나 세미콜론을위한 필요없이)도 새로운 라인 분리도 작동합니다 생각합니다.

+0

시도해 주셔서 감사합니다. 아직 작동하지 않습니다. –

+0

'trial1.jerseytutorial'의 클래스가 작동합니까? –

+0

작동하지 않습니다. 내가 "하위 패키지"를 만들었지 만 패키지가 아닌 것 같습니다. 따라서, 난 그냥 사용해야 : jersey.config.server.provider.packages trial1.jerseytutorial 내 자바 클래스에 , 내 패키지와 이름을 수 : trial1를 .jerseytutorial.Profile 그냥 프로필 대신에. 아직 다른 패키지를 만드는 방법에 대해 혼란 스럽지만, 패키지는 아닙니다. –