java报错之There is already ... bean method ... mapped

运行程序,console报如下错误

Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'sprayRobotController' method com.mongodb.controller.sprayRobotController#getRoomDisplayName(String, String) to {GET /sprayRobot/getRoutePoint, produces [application/json;charset=utf-8]}: There is already 'sprayRobotController' bean method com.mongodb.controller.sprayRobotController#getRoutePoint(String, String, Integer) mapped.

说人话

仔细看,大概在说无法将getRoomDisplayName(String, String)映射给“GET /sprayRobot/getRoutePoint”的get请求,是因为已经有bean方法getRoutePoint(String, String, Integer)被映射了。

分析

其实就是在说,名为“getRoutePoint”的请求已经有getRoutePoint(String, String, Integer)方法对应了,无法再将getRoomDisplayName(String, String)映射给该请求。一个请求不能映射两个bean方法。

解决

原来是希望名为“getRoomDisplayName”的请求可以映射到getRoomDisplayName(String, String)方法,修改@RequestMapping的value(如getRoomDisplayName)即可。

你可能感兴趣的:(java,java)