2014-11-18 1 views
0

나는 경로를 하드 코딩하지 말고 오히려 우리가 필요에 따라 변경할 수있는 속성에서 선택해야합니다. ---저지에서 속성 파일의 경로 값을 어떻게 지정합니까?

@Path("ws/{version}") 
public class DesignationResource { 

    @PathParam("version") String version = 
       Constants.API_VERSION; //(read from property file in class Constants) 
    @PathParam("servicename_designationList") String servicename_designationList= 
       Constants.API_POST_CITYLIST_NAME ; //(read from property file in class Constants) 



    @Path("{servicename_designationList}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public Response getDesignations() 
    { 
     /** 
     ...CODES... 
     */ 
    } 
} 

하지만 클래스가 노력하고 던지는되지 예외 다음

코드의 두 가지 방법이있는 경우 : 코드 아래

작동 ---를

@Path("ws/{version}") 
public class DesignationResource { 

    @PathParam("version") String version = 
       Constants.API_VERSION; //(read from property file in class Constants) 
    @PathParam("servicename_designationList") String servicename_designationList= 
       Constants.API_POST_CITYLIST_NAME ; //(read from property file in class Constants) 
    @PathParam("servicename_designationListId") String servicename_designationListId= 
       Constants.API_POST_CITYLISTID_NAME ; //(read from property file in class Constants) 



    @Path("{servicename_designationList}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public Response getDesignations() 
    { 
     /** 
     ...CODES... 
     */ 
    } 

    @Path("{servicename_designationListId}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public Response getDesignationsId() 
    { 
     /** 
     ...CODES... 
     */ 
    } 
} 

는 예외 기록 예 : -----

 
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. 
[[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by @Consumes and @Produces annotations at Java methods public javax.ws.rs.core.Response DesignationResource.getDesignations() and public javax.ws.rs.core.Response DesignationResource.getDesignationsId() at matching regular expression /([^/]+?). These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.; source='[email protected]', [FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by @Consumes and @Produces annotations at Java methods public javax.ws.rs.core.Response source='[email protected]'] 
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:465) 
    ... 
+0

각 방법의 목적은 무엇이며 각 URL에 보낼 예제 URL을 제공 할 수 있습니까? –

+0

서비스 URL이 속성 파일에 의해 제어되기를 원합니다. getDesignations() URl을 호출한다고 가정하면 http://192.168.1.46:9090/api/ws/v1/designations 다음에 나중에 내 URL이 http://192.168.1.46:9090/api/ws/이되기를 원합니다. 같은 목적을위한 v1/desig 그럼 내 .java가 아닌 내 속성 파일을 변경해야합니다 –

답변

1

메서드에서 동일한 경로 url (servicename_designationListId)을 사용하고 있습니다. 아래와 같이 메소드에 다른 경로를 지정하십시오.

@Path("{servicename_designations}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public Response getDesignations() 
    { 
     /** 
     ...CODES... 
     */ 
    } 

    @Path("{servicename_designationListId}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public Response getDesignationsId() 
    { 
     /** 
     ...CODES... 
     */ 
    } 
+0

다른 경로 URL을 사용하고있었습니다. 업데이트 된 질문 문제가 계속됩니다. –

+0

새 스택 추적을하십시오. –

+0

동일한 예외 로그 –

0

stacktrace에서 말한 것처럼 경로는 고유해야합니다 (또는 다른 미디어 유형을 사용해야합니다). 제 생각에는 다음과 같이하고 싶습니다.

@Path(Constants.API_POST_CITYLIST_NAME) 
@Produces(MediaType.APPLICATION_JSON) 
public Response getDesignations() 
{ 
    /** 
    ...CODES... 
    */ 
} 

@Path(Constants.API_POST_CITYLISTID_NAME) 
@Produces(MediaType.APPLICATION_JSON) 
public Response getDesignationsId() 
{ 
    /** 
    ...CODES... 
    */ 
} 
+0

이 @Path (Constants.API_POST_CITYLISTID_NAME)는 Constants.API_POST_CITYLISTID_NAME = "<일부 하드 코딩 된 문자열>"과 Constants.API_POST_CITYLISTID_NAME = property.getproperty ("")가 아닌 경우에만 유효합니다. –

+0

예, 주석의 값은 컴파일 시간 상수 여야합니다. 따라서 유일한 해결책은 소스 파일 (클래스 상수)의 자리 표시자를 속성 파일의 값으로 대체하는 일종의 컴파일 시간 도구 (maven)를 사용하는 것입니다. – braunpet

0

the programmatic API을 사용하여 리소스를 등록하십시오. 어노테이션을 통해 관리 할 수없는 방식으로 런타임에 동적으로 등록 할 수 있습니다.