本文主要是介绍springboot 打印 RequestMapping 信息配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Spring Boot 2.1 之前的版本
Spring Boot 2.1 之前 使用INFO 级别记录的信息很多,所以只需要配置为INFO程序启动的时候就可以打印 RequestMapping 的信息,示例如下:
logging:level:root: info
打印出来的格式如下:
2019-04-02 19: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-04-02 19: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-04-02 19: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-04-02 19: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-04-02 19: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-04-02 19: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-04-02 19: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-04-02 19: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)
Spring Boot 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: infoorg.mybatis: debugjava.sql: debugorg.springframework.web: trace
日志输出格式如下:把每个Controller下面的所有RequestMapping全部列到一个Controller下面,打印格式比之前的格式可读性和区分性更好一些
2019-04-02 19: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-04-02 19:55:22.247 TRACE 13313 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : c.z.q.w.c.IndexController:{GET /index}: homePage()
2019-04-02 19:55:22.248 TRACE 13313 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : c.z.q.w.c.RetryController:{ /order/create}: list(Integer)
2019-04-02 19: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)
这篇关于springboot 打印 RequestMapping 信息配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!