• 根据日志分析异常: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;
        }

    异常:

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

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

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

    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的异常捕获里面打断点,可以直观的看到问题所在。因为有些异常日志不会打印。

  • 相关阅读:
    C语言之指针基础概念
    Android之常用功能代码
    Android之ImageButton控件基础操作
    BZOJ1079或洛谷2476 [SCOI2008]着色方案
    HDOJ2870 Largest Submatrix
    BZOJ1855或洛谷2569 [SCOI2010]股票交易
    BZOJ1233 [Usaco2009Open]干草堆tower
    HDOJ4261 Estimation
    POJ3254或洛谷1879 Corn Fields
    POJ1037 A Decorative Fence
  • 原文地址:https://www.cnblogs.com/miaoying/p/10137407.html
Copyright © 2020-2023  润新知