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

时间:2021-11-11 18:31:27

在使用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‘

 

 

说的