• springboot启动打印controller映射url


    1. springboot启动打印controller映射url日志
    2023-10-11 14:09:46.482 TRACE 27244 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 
    	c.d.c.j.w.c.LabelConfigController:
    	{POST [/labelConfig/add]}: add(LabelConfig)
    	{POST [/labelConfig/update]}: update(LabelConfig)
    	{GET [/labelConfig/delete]}: delete(Integer)
    	{POST [/labelConfig/list]}: list(LabelConfig)
    	{GET [/labelConfig/detail]}: detail(Integer)
    	{POST [/labelConfig/page]}: page(LabelConfig,Page)
    2023-10-11 14:09:46.486 TRACE 27244 --- [           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)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    2. 分析AbstractHandlerMethodMapping源码
    protected void detectHandlerMethods(Object handler) {
    		Class handlerType = (handler instanceof String ?
    				obtainApplicationContext().getType((String) handler) : handler.getClass());
    
    		if (handlerType != null) {
    			Class userType = ClassUtils.getUserClass(handlerType);
    			Map methods = MethodIntrospector.selectMethods(userType,
    					(MethodIntrospector.MetadataLookup) method -> {
    						try {
    							return getMappingForMethod(method, userType);
    						}
    						catch (Throwable ex) {
    							throw new IllegalStateException("Invalid mapping on handler class [" +
    									userType.getName() + "]: " + method, ex);
    						}
    					});
    			if (logger.isTraceEnabled()) {
    				logger.trace(formatMappings(userType, methods));
    			}
    			else if (mappingsLogger.isDebugEnabled()) {
    				mappingsLogger.debug(formatMappings(userType, methods));
    			}
    			methods.forEach((method, mapping) -> {
    				Method invocableMethod = AopUtils.selectInvocableMethod(method, userType);
    				registerHandlerMethod(handler, invocableMethod, mapping);
    			});
    		}
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    注意:低版本spring-webmvc-5.2.13.RELEASE.jar没有

    else if (mappingsLogger.isDebugEnabled()) {
    	mappingsLogger.debug(formatMappings(userType, methods));
    }
    
    • 1
    • 2
    • 3
    3. yml配置日志
    logging:
      level:
        root: INFO
        # 低版本spring-webmvc-5.2.13.RELEASE.jar
        org.springframework.web: TRACE
        # 高版本spring-webmvc-5.3.13.jar
    #    _org.springframework.web: DEBUG
    
    开启  _org.springframework.web: DEBUG 时日志
    2023-10-11 14:23:54.649 DEBUG 30144 --- [           main] _.s.web.servlet.HandlerMapping.Mappings  : 
    	c.d.c.j.w.c.LabelConfigController:
    	{POST [/labelConfig/add]}: add(LabelConfig)
    	{POST [/labelConfig/update]}: update(LabelConfig)
    	{GET [/labelConfig/delete]}: delete(Integer)
    	{POST [/labelConfig/list]}: list(LabelConfig)
    	{GET [/labelConfig/detail]}: detail(Integer)
    	{POST [/labelConfig/page]}: page(LabelConfig,Page)
    2023-10-11 14:23:54.653 DEBUG 30144 --- [           main] _.s.web.servlet.HandlerMapping.Mappings  : 
    	o.s.b.a.w.s.e.BasicErrorController:
    	{ [/error]}: error(HttpServletRequest)
    	{ [/error], produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)	
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
  • 相关阅读:
    java基于Spring boot+vue的点餐外卖订餐系统-商家-用户-骑手
    SSM框架Demo: 简朴博客系统
    VGW在 Windows 平台上局域网就绪的旁路由器程序
    GB/T 28181联网系统通信协议结构和技术实现
    浅谈web性能测试
    我的第一个 Intellij 插件上线了
    java基于springboot+vue的疫情网课管理系统 elementui
    电脑显示不出网络
    基于springboot构建的mysql接口实现读写,并提供给宜搭使用
    sklearn.datasets--学习笔记
  • 原文地址:https://blog.csdn.net/m0_37539286/article/details/133769136