我希望路径不应该被硬编码,而是从属性中获取,以便我们可以根据需要更改它。
以下代码有效:---
@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:应用程序资源模型的验证在应用程序初始化期间失败。 [[致命] 资源模型具有用于 HTTP 方法 GET 和输入 mime 类型的模糊(子)资源方法,如 Java 方法中的 @Consumes 和 @Produces 注释定义 public javax.ws.rs.core.Response DesignationResource.getDesignations( ) 和公共 javax.ws.rs.core.Response DesignationResource.getDesignationsId() 匹配正则表达式 /([^/]+?)。这两种方法产生和使用完全相同的 mime 类型,因此它们作为资源方法的调用总是会失败。source='org.glassfish.jersey.server.model.RuntimeResource@7e5ba613', [FATAL] 资源模型具有用于 HTTP 方法 GET 的模糊(子)资源方法以及由 @Consumes 和 @Produces 注释定义的输入 mime 类型在 Java 方法 public javax.ws.rs.core.Response source='org.glassfish.jersey.server.model.RuntimeResource@7e5ba613'] 在 org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:465) ...