RESTEASY002142:多个资源方法匹配请求

ska*_*kal 5 java rest jax-rs resteasy

我正在关注两个完全不同的URL,我无法解释原因:

RESTEASY002142: 

   Multiple resource methods match request "GET /devices/distinctValues/3". 
   Selecting one. 

Matching methods: 
[public javax.ws.rs.core.Response 
mypackage.DevService.getDistinctValues(int) throws java.lang.Exception, 

public javax.ws.rs.core.Response 
mypackage.DevRESTService.getDevice(int,java.lang.String) 
throws java.lang.Exception]
Run Code Online (Sandbox Code Playgroud)

由于URLS完全不同,因此不应出现此警告.如果有人知道为什么会这样:

两种方法的网址:

getDevice:

@GET
@Path("devices/{customerId}/{deviceIds}")
@Produces({ "application/json" })
Run Code Online (Sandbox Code Playgroud)

getDistinctValues:

@GET
@Path("devices/distinctValues/{customerId}")
@Consumes("application/json")
@Produces("application/json")
Run Code Online (Sandbox Code Playgroud)

use*_*551 8

发生警告是因为您的请求字符串可以匹配两个路径模板.请求"devices/distinctValues/3"

  • devices/distinctValues/{customerId}在那匹配customerId = "3"
  • 匹配devices/{customerId}/{deviceIds}在那customerId = "distinctValues"deviceIds = "3".

没有类型解析,因为您的请求String是无法判断customerId它无法接受"distinctValues".

作为一种解决方法,您可以指定链接问题中显示的正则表达式,也可以使用RESTEasy代理框架,它基本上是服务器(您的JAX-RS资源)和客户端使用的共享接口,然后您使用共同语言具有类型分辨率.请注意,文档示例中存在拼写错误.