• Springboot 2.X的RequestMapping 的映射路径怎么看不到了?


    在使用spring boot 1.X的时候我们可以在console中看到mapping的映射路径

    1 2020-01-12 19:10:19.996  INFO 2711 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
    2 2020-01-12 19:10:19.997  INFO 2711 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
    3 2020-01-12 19:10:20.026  INFO 2711 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    4 2020-01-12 19:10:20.026  INFO 2711 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    5 2020-01-12 19:10:20.065  INFO 2711 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    6 2020-01-12 19:10:20.422  INFO 2711 --- [           main] uration$$EnhancerBySpringCGLIB$$8e8eae03 : No deployment resources were found for autodeployment
    7 2020-01-12 19:10:20.574  INFO 2711 --- [           main] uration$$EnhancerBySpringCGLIB$$e60feff5 : No deployment resources were found for autodeployment
    8 2020-01-12 19:10:20.614  INFO 2711 --- [           main] uration$$EnhancerBySpringCGLIB$$2a356a63 : No deployment resources were found for autodeployment

    开发的时候有这个可以方便的解决404的问题,可以看看自己新添加的接口有没有映射上去。

    为什么我升级为2.2.1就不行了呢。。

    一番查找之后发现

    Spring Boot 2.1 以后 使用了 Spring Framework 5.1, 而 Spring Framework 5.1 对日志做了较大的改动。现在使用 INFO 级别记录的信息非常少,DEBUG 级别提供了更多信息,但不详细。只有 TRACE 级别才会提供详细信息。这时候为了要打印Controller里面的 RequestMapping信息需要把org.springframework.web打印日志的格式设置为trace,示例如下:

    logging:
      level:
        # root: info
        # org.mybatis: debug
        # java.sql: debug
        org.springframework.web: trace

     加上日志级别后终于出来了

    2020-01-12 19:19:01.286 TRACE 3010 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 
        o.s.b.a.w.s.e.BasicErrorController:
        { /error}: error(HttpServletRequest)
        { /error, produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)
    2020-01-12 19:19:01.291 DEBUG 3010 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'

     或者 也是可以的

    logging:
      level:
        web: trace
        sql: debug  # mybatis 日志
       root:info # 本项目日志 info

      

  • 相关阅读:
    raspbian设置locale
    docker redis
    consul开发部署集群
    自动更新ssh登录的key到远程主机
    docker官方脚本阿里云镜像
    nodejs中国镜像
    github修改hosts加速
    docker容器更新总是自动重启
    webstrom不显示右边的竖线,代码结构线
    _mssql.c:266:22: fatal error: sqlfront.h: No such file or directory
  • 原文地址:https://www.cnblogs.com/munan56/p/12184385.html
Copyright © 2020-2023  润新知