我有一个基本的 SpringBoot 2.0.6.RELEASE 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为具有 Restful 架构的可执行 JAR@PutMapping(path = "/users/alarms2", consumes = "application/json", produces = "application/json") public void setAlerts2(@RequestHeader(value = "Authorization") String authHeader, @RequestBody AlertConfiguration alertConfiguration) throws DataAccessException, ClientProtocolException, SQLException, IOException {..}但是当我从 curl 调用这个方法时:curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJyaWNhcmQub2SAsZUBnbWFpbC5jb20iLCJleHAiOjE2MDAxODMzNDAsImlhdCI6MTUzOTcwMzM0MH0.2gbyyGnkcoHjOw7HbUBBQgb59Bw8iAyFbqTe2DPUlOA-V5UwrW3KXWHZlXssZni8oRJ_o1QRzAFtAWMfz7f0Yw" -d ‘{“symbol": “MENU”, "alarmKey”:”VEGAN” , "enabled": "true"}' "http://95.90.225.68:1133/restos/api/v1/users/alarms2"我在服务器中收到此错误:2018-10-17 17:16 [http-nio-1133-exec-9] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver.resolveException(140) - Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: "alarms2"]
1 回答
LEATH
TA贡献1936条经验 获得超6个赞
您可能有另一种具有更通用签名的方法,该方法与给定的签名重叠。就像是:
@PutMapping(path = "/users/{userId}", ...)
public void someMethod(@PathVariable(value = "userId") Long userId) {
...
}
因此,当您使用/api/v1/users/alarms2Spring 时,首先尝试将“alarms2”(显然不是有效的Long)转换为userId(是Long)
添加回答
举报
0/150
提交
取消