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,示例如下: