Java 如何从jersey中的属性文件指定路径值?

Java 如何从jersey中的属性文件指定路径值?,java,jersey,jersey-2.0,jersey-1.0,Java,Jersey,Jersey 2.0,Jersey 1.0,我希望路径不应该硬编码,而应该从属性中提取,以便我们可以根据需要更改它 以下代码工作:--- 但是如果类有两个方法,那么它将不工作并引发异常 代码:--- 例外情况记录为:----- org.glassfish.jersey.server.model.ModelValidationException:应用程序资源模型的验证在应用程序初始化期间失败。 [[FATAL]资源模型在匹配正则表达式处的Java方法public javax.ws.rs.core.Response-DesignationRe

我希望路径不应该硬编码,而应该从属性中提取,以便我们可以根据需要更改它

以下代码工作:---

但是如果类有两个方法,那么它将不工作并引发异常

代码:---

例外情况记录为:-----

org.glassfish.jersey.server.model.ModelValidationException:应用程序资源模型的验证在应用程序初始化期间失败。 [[FATAL]资源模型在匹配正则表达式处的Java方法public javax.ws.rs.core.Response-DesignationResource.getDesignations()和public javax.ws.rs.core.Response-DesignationResource.getDesignationsId()中为HTTP方法GET和input mime类型定义了不明确的(子)资源方法/([^/]+?)。这两个方法产生和使用完全相同的mime类型,因此它们作为资源方法的调用将始终失败。;source='org.glassfish.jersey.server.model。RuntimeResource@7e5ba613“,[FATAL]资源模型具有不明确性(子-)HTTP方法获取和输入mime类型的资源方法由@Consumes和@products在Java methods public javax.ws.rs.core.Response source='org.glassfish.jersey.server.model定义。RuntimeResource@7e5ba613'] 位于org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:465) ...
您在方法中使用了相同的路径url(servicename\u designationListId)。请为您的方法指定不同的路径,如下所示

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

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

正如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...
    */
}

用于注册资源。它将允许您在运行时以无法通过批注管理的方式动态注册内容。

我使用了不同的路径Url。更新后的问题仍然存在。请提供新的堆栈跟踪。每个方法的用途是什么,您能举一个示例Url发送给每个方法吗nt我的服务URL由属性文件控制。假设在将来某个时候调用getDesignations()URL,我希望我的URL具有相同的用途,那么我必须更改我的属性文件而不是.javaThis@Path(Constants.API_POST_citylisid_NAME)仅在Constants.API_POST_citylisid_NAME=“”时有效不是常量。API\u POST\u CITYLISTID\u NAME=property.getproperty(“”)是的,注释的值必须是编译时常量。因此,我认为,唯一的解决方案是使用某种编译时工具(maven)将源代码(类常量)中的占位符替换为属性文件中的值。 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='org.glassfish.jersey.server.model.RuntimeResource@7e5ba613', [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='org.glassfish.jersey.server.model.RuntimeResource@7e5ba613'] at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:465) ...
@Path("{servicename_designations}")
  @Produces(MediaType.APPLICATION_JSON)
    public Response getDesignations()
    {
       /**
         ...CODES...
        */
    }

  @Path("{servicename_designationListId}")
  @Produces(MediaType.APPLICATION_JSON)
    public Response getDesignationsId()
    {
       /**
         ...CODES...
        */
    }
@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...
    */
}