首页 > 其他分享 >jeecgboot启动时日志打印所有接口,作为开发时的参考作用吧。

jeecgboot启动时日志打印所有接口,作为开发时的参考作用吧。

时间:2023-04-27 18:23:09浏览次数:31  
标签:name 接口 method api jeecgboot path 日志 port String

主要的方式是使用了RequestMappingHandlerMapping这个bean当中保存了所有的映射、对应的controller类、方法等等的信息。在单体启动类中取出这个bean然后遍历就可以了,代码如下:

/**
* 单体启动类(采用此类启动为单体模式)
*/
@Slf4j
@SpringBootApplication
public class JeecgSystemApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(JeecgSystemApplication.class);
    }

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
        log.info("\n----------------------------------------------------------\n\t" +
                "Application Jeecg-Boot is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");
        //获取所有的接口,打印出来,作为参考
        RequestMappingHandlerMapping requestMappingHandlerMapping = application.getBean(RequestMappingHandlerMapping.class);
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
        for(RequestMappingInfo requestMappingInfo : handlerMethods.keySet()){
            Set<String> setPatterns = requestMappingInfo.getPatternsCondition().getPatterns();
            Set<RequestMethod> setMethods = requestMappingInfo.getMethodsCondition().getMethods();
            String pattern = "";
            if(setPatterns.iterator().hasNext()){
                pattern = setPatterns.iterator().next();
            }
            String method = "";
            if(setMethods.iterator().hasNext()){
                method = setMethods.iterator().next().toString();
            }
            HandlerMethod handlerMethod = handlerMethods.get(requestMappingInfo);
            log.info("----- " + getApiName(handlerMethod.getBeanType()) + ":" + getOperationName(handlerMethod.getMethod()));
            log.info("----- key:" + method + " " + pattern);
            log.info("----- url:" + "http://" + ip + ":" + port + path + pattern);
            log.info("********************************************************************");
        }

    }

    private static String getApiName(Class<?> clazz) {
        String name = clazz.getName();
        Api api = clazz.getAnnotation(Api.class);
        if (api != null && StringUtils.isNotBlank(api.value())) {
            name = api.value();
        }
        if (api != null && api.tags().length > 0) {
            name = String.join(",",api.tags());
        }
        return name;
    }

    private static String getOperationName(Method method) {
        String name = method.getName();
        ApiOperation operation = method.getAnnotation(ApiOperation.class);
        if (operation != null && StringUtils.isNotBlank(operation.value())) {
            name = operation.value();
        }
        return name;
    }

}

 

标签:name,接口,method,api,jeecgboot,path,日志,port,String
From: https://www.cnblogs.com/lengho123/p/17359901.html

相关文章

  • SpringBoot配置日志文件定期切割
    下面是我的配置:创建logback-spring.xml写入下面的配置<?xmlversion="1.0"encoding="UTF-8"?><configurationdebug="false"><!--定义日志文件的存储地址勿在LogBack的配置中使用相对路径--><propertyname="LOG_HOME"value=&quo......
  • 接口开发文档及注意事项
    接口开发是指通过定义一组接口,使不同的系统或设备之间能够进行数据通信和互操作的过程。以下是一些在接口开发过程中需要注意的事项:  接口定义:在定义接口时,需要明确接口的输入输出参数、数据类型、异常处理等信息,以确保不同的系统或设备之间能够正确地交换数据。  接口实现......
  • API 接口规范
    [API接口规范-BNDong-博客园](https://www.cnblogs.com/bndong/p/6139598.html)整体规范建议采用RESTful方式来实施。协议API与客户端通讯协议主要包含 http 和 https,建议使用 https 确保交互数据的传输安全。域名应该尽量将API部署在专用域名之下。Gohttps:/......
  • lazada按关键字搜索商品API接口
    ​lazada按关键字搜索商品API接口,在lazada上搜索产品,如果只需要搜索单个产品的话,那么直接在搜索框输入“关键字”即可,如果需要多个产品,那么则需要进行关键字扩展。lazada按关键字搜索商品API接口分为两部分:1.查询列表部分:在列表部分输入“关键字”,即可查询到对应的商品列表;2......
  • 通过NG做用户登录验证接口返回的返回体做登录接口判断
    ng获取响应体的json里面的字段需要安装第三方模块ngx_devel_kit的ngx_http_set_misc_module的set_json_var指令,form-input-nginx-modulelocation/api{proxy_passhttp://backend;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;pro......
  • Kivy中的Logger组件用于记录应用程序的日志信息
    name:可选参数,指定Logger组件的名称。默认为root。level:可选参数,指定Logger组件的记录级别。默认为debug。propagate:可选参数,指定是否向父Logger组件传递记录消息。默认为True。handlers:可选参数,指定Logger组件的处理程序。默认为None。disabled:可......
  • API数据接口该怎么对接
    随着互联网和移动互联网的发展,API(ApplicationProgrammingInterface)接口的作用越来越重要。API接口将各种平台相互连接,使得不同系统的信息可以互相获取和使用,大大提高了系统的互操作性和开发效率。本文将介绍如何对接API数据接口,以及注意事项和技巧。获取API接口首先需要找到需要......
  • API淘宝数据接口
    如果你想在自己的应用中使用淘宝的数据,那么对接淘宝数据接口是必不可少的一步。本文将介绍如何对接API淘宝数据接口,以便你能够顺利获取和使用淘宝的数据。步骤一:获取AppKey和AppSecret首先,在淘宝开放平台申请API接口之前,需要先注册为淘宝开发者并创建应用。创建应用后,你将得到一......
  • vue中实际代码模拟JS中promise调接口的运行流程
    假设我们有一个需要调用接口的场景,我们可以使用Vue中的axios库来发送请求。以下是一个简单的例子://引入axios库importaxiosfrom'axios'//定义一个函数,用于发送请求functionfetchData(){//返回一个Promise对象returnnewPromise((resolve,reject)=>{//发......
  • 隧道全幅表观产品开发日志(一)旧版软件的修改日志
    好久没写博客了,上一次写还是在上一家公司现在在的这家公司目前做的是隧道内的探伤项目,我现在主要的工作是做工控机,也就是控制各种硬件组织作业。目前的产品架构见https://github.com/LeventureQys/South_Gathering_Doc中多设备采集软件相关内容,这篇文章仅是记录旧版软件的修改......