springboot获取项目中的所有接口信息

硅谷探秘者 Md 框架 1690 0 0

springboot获取项目中所有对外提供的接口信息

@Component
public class Test implements ApplicationRunner {

    @Resource
    private ApplicationContext applicationContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        RequestMappingHandlerMapping mappings = applicationContext.getBean(RequestMappingHandlerMapping.class);
        Map<RequestMappingInfo, HandlerMethod> requestMappingInfoHandlerMethodHashMap = new HashMap<>(mappings.getHandlerMethods());
        requestMappingInfoHandlerMethodHashMap.forEach((requestMappingInfo, handlerMethod) -> {
            Set<RequestMethod> requestType = new HashSet<>(requestMappingInfo.getMethodsCondition().getMethods());
            StringJoiner type = new StringJoiner(",");
            for (RequestMethod requestMethod : requestType) {
                type = type.add(requestMethod.name());
            }
            String url = new ArrayList<>(requestMappingInfo.getPatternsCondition().getPatterns()).get(0);
            // 全类名 + 方法名
            System.out.print(new StringBuilder(handlerMethod.getBeanType().getName()).append(".").append(handlerMethod.getMethod().getName()).toString());
            // 请求地址
            System.out.print("\t"+url);
            // 请求方式
            System.out.println("\t"+type.toString());
        });
    }
}

评论区
请写下您的评论...
暂无评论...
猜你喜欢
工具 3982 一个工具类即可packagecom.dzqc.yx.util;importorg.springframework.beans.BeansException;importorg.springframework.context.ApplicationContext;importorg.springframework.context.ApplicationContextAware;importorg.s
算法基础 1867 如果一个类实现了一个,如何泛型实际类型importjava.lang.reflect.ParameterizedType; importjava.lang.reflect.Type
spring/springmvc 1929 WebApplicationContextwebApplicationContext=ContextLoader.getCurrentWebApplicationContext();ServletContextcontext=webApplicationContext.getServletContext();
工具 2351 1.修改配置url填外网可以访问(必须是80端),如果是本地测试话可以用外网穿透。例:http://aaaa.com/call/backToken可以任意填写,但要和配置一致例
微信 java 1557 自动登录openid和用户 测试代码
spring/springmvc 1400 "spring在ioc容器aop受理对象",这句话是什么意思呢?时候我们会在spring对一下类进行代理,比如我们会用springaop和自定义注解对一些访问添加日志,再比如对
框架 7552 springboot启动后执行特定方法需求,需要启动时候向数据库查询一下系统属性,或者需要加载某个特定方法。那么在springboot可以用如下方法实现第一种实现,实现
前端,java基础 1508 一、pom依赖二、后端示例三、前端页面  些场景需要生成带参数小程序二维码,比如商城为每个商品生成小程序二维码,通过微扫码直跳转到该商品展示页面。微为开发者们提供了相应
归档
2018-11  12 2018-12  33 2019-01  28 2019-02  28 2019-03  32 2019-04  27 2019-05  33 2019-06  6 2019-07  12 2019-08  12 2019-09  21 2019-10  8 2019-11  15 2019-12  25 2020-01  9 2020-02  5 2020-03  16 2020-04  4 2020-06  1 2020-07  7 2020-08  13 2020-09  9 2020-10  5 2020-12  3 2021-01  1 2021-02  5 2021-03  7 2021-04  4 2021-05  4 2021-06  1 2021-07  7 2021-08  2 2021-09  8 2021-10  9 2021-11  16 2021-12  14 2022-01  7 2022-05  1 2022-08  3 2022-09  2 2022-10  2 2022-12  5 2023-01  3 2023-02  1 2023-03  4 2023-04  2 2023-06  3 2023-07  4 2023-08  1 2023-10  1 2024-02  1 2024-03  1 2024-04  1
标签
算法基础 linux 前端 c++ 数据结构 框架 数据库 计算机基础 储备知识 java基础 ASM 其他 深入理解java虚拟机 nginx git 消息中间件 搜索 maven redis docker dubbo vue 导入导出 软件使用 idea插件 协议 无聊的知识 jenkins springboot mqtt协议 keepalived minio mysql ensp 网络基础 xxl-job rabbitmq haproxy srs 音视频 webrtc javascript
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。