zoukankan      html  css  js  c++  java
  • 根据日志分析异常: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的异常捕获里面打断点,可以直观的看到问题所在。因为有些异常日志不会打印。

  • 相关阅读:
    Ubuntu下SVN命令行递归加入文件夹文件(免去一个一个的加入 --force)
    oschina插件和扩展
    oschina iOS代码库
    oschina 开发工具
    oschina应用工具
    oschina程序开发
    网络爬虫 kamike.collect
    WebFetch 是无依赖极简网页爬取组件
    commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现
    JAVA平台上的网络爬虫脚本语言 CrawlScript
  • 原文地址:https://www.cnblogs.com/miaoying/p/10137407.html
Copyright © 2011-2022 走看看