根据日志分析异常:There is already 'XXX' bean method

问题代码:

@Slf4j
@Api(value = "paymentOrderController", description = "PaymentOrderController api")
@RestController
@RequestMapping(value = "/auth/hospital/payment/order")
public class PaymentOrderController { @RequestMapping(method = RequestMethod.GET, name = "/updatePaymentOrder")
int updatePaymentOrder(@RequestParam("paymentOrderId") String paymentOrderId, @RequestParam("orderStatus") String orderStatus) {
return 0;
} @RequestMapping(method = RequestMethod.GET, name = "/selectList")
List<TPaymentOrder> selectList(@RequestParam("businessId") String businessId, @RequestParam("businessType") String businessType) {
return null;
}

异常:

根据日志分析异常:There is already 'XXX' bean method

从以上日志中可以看出paymentOrderController中存在同样的方法,且指明 selectList 、updatePaymentOrder存在多个。

但是全局搜索关键字后,确定没有多个该方法。

可以配置日志打印出spring boot加载的所有Bean及其Method,追踪打印日志,以updatePaymentOrder为关键词搜索,可看到:

根据日志分析异常:There is already 'XXX' bean method

updatePaymentOrder的Mapped为:Mapped "{[/auth/hospital/payment/order],methods=[GET]}"......

明显有问题,正常的应该是:Mapped "{[/auth/hospital/payment/order/updatePaymentOrder],methods=[GET]}"

由此可知, selectList 、updatePaymentOrder两个方法的请求路径写的有问题,对比其他正常的请求,可知:

在@RequestMapping中,路径的键应该是value或者path,而不能是name,否则会默认为类指定的path或者/

@RequestMapping(method = RequestMethod.GET, value = "/updatePaymentOrder")

注:Spring Boot项目启动遇到问题抛异常时,可直接在SpringApplication的run的异常捕获里面打断点,可以直观的看到问题所在。因为有些异常日志不会打印。

根据日志分析异常:There is already 'XXX' bean method

上一篇:201521123116 《java程序设计》第十三周学习总结


下一篇:oracle 多行转多列查询