Spring Boot之版本更新的配置变动

  |  

Spring Boot的版本升级带来的配置及特性都有发生改变,搭建框架时碰到,特此记录

打印RequestMapping信息配置

2.1之前的版本

Spring Boot 2.1 之前 使用INFO 级别记录的信息很多,所以只需要配置为INFO程序启动的时候就可以打印 RequestMapping 的信息,示例如下:

1
2
3
logging:
level:
root: info

打印出来的格式如下:

1
2
3
4
5
6
7
8
2019-05-23 16:51:45.824  INFO 13218 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/board/add]}" onto public com.ztd.question.util.ResultVo com.ztd.question.web.controller.BoardController.add(com.ztd.question.web.entity.Board)
2019-05-23 16:51:45.826 INFO 13218 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/board/update]}" onto public com.ztd.question.util.ResultVo com.ztd.question.web.controller.BoardController.update(com.ztd.question.web.entity.Board)
2019-05-23 16:51:45.827 INFO 13218 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/board/saveList]}" onto public com.ztd.question.util.ResultVo com.ztd.question.web.controller.BoardController.update(com.ztd.question.web.entity.Board[])
2019-05-23 16:51:45.827 INFO 13218 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/board/delete/{id}]}" onto public com.ztd.question.util.ResultVo com.ztd.question.web.controller.BoardController.delete(java.lang.Integer)
2019-05-23 16:51:45.828 INFO 13218 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/board/list]}" onto public com.ztd.question.util.ResultVo<java.util.List<com.ztd.question.web.entity.Board>> com.ztd.question.web.controller.BoardController.list(java.lang.String)
2019-05-23 16:51:45.830 INFO 13218 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/index],methods=[GET]}" onto public java.lang.String com.ztd.question.web.controller.IndexController.homePage()
2019-05-23 16:51:45.831 INFO 13218 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/order/create]}" onto public com.ztd.question.util.ResultVo<java.lang.Object> com.ztd.question.web.controller.RetryController.list(java.lang.Integer) throws java.lang.Exception
2019-05-23 16:51:45.834 INFO 13218 --- [ 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.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)

2.1之后的版本

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

1
2
3
4
5
6
logging:
level:
root: info
org.mybatis: debug
java.sql: debug
org.springframework.web: trace

日志输出格式如下:把每个Controller下面的所有RequestMapping全部列到一个Controller下面,打印格式比之前的格式可读性和区分性更好一些

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2019-05-23 16:55:22.241 TRACE 13313 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 
c.z.q.w.c.BoardController:
{ /board/add}: add(Board)
{ /board/update}: update(Board)
{ /board/saveList}: update(Board[])
{ /board/delete/{id}}: delete(Integer)
{ /board/list}: list(String)
2019-05-23 16:55:22.247 TRACE 13313 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :
c.z.q.w.c.IndexController:
{GET /index}: homePage()
2019-05-23 16:55:22.248 TRACE 13313 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :
c.z.q.w.c.RetryController:
{ /order/create}: list(Integer)
2019-05-23 16:55:22.253 TRACE 13313 --- [ 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)
个人微信公众号技术交流QQ群
文章目录
  1. 1. 打印RequestMapping信息配置
    1. 1.1. 2.1之前的版本
    2. 1.2. 2.1之后的版本