支持从springboot的war包运行时从classes以及jar包中读取类信息

支持按包扫描class中所有的Controller接口

功能:

支持java -jar **.war的模式,以反射形式按包名扫描所有的类(含jar包中的类),以便于获取类的:接口,注解,以及接口注解的属性值等信息

 按包名扫描class中所有的Controller接口(支持从springboot的war中再查找jar包中的类)

 同时支持扫描class中的Annotation注解及注解的属性值

/**
     * 从类中直接加载所有controller类的接口信息
     * 并可与正在运行的接口关联
     *
     * @param request   HttpServletRequest
     * @param requestVo RequestVo
     * @return ResultData
     */
    @RequestMapping(value = "/requestScans", method = {RequestMethod.POST, RequestMethod.GET})
    @CheckLogin
    public ResultData requestScans(HttpServletRequest request, RequestVo requestVo
            , @RequestParam(value = "type", required = false, defaultValue = "current") String type
            , @RequestParam(value = "day", required = false, defaultValue = "-1") Integer day) {
        String token = RequestUtils.getToken(request);
        UserVo userVo = dflUserLoginBiz.getUserByToken(token);
        checkUserPermission(userVo, UserOperType.VIEW);
        String pkg = request.getParameter("pkg");
        pkg = (String) CommUtils.nvl(pkg, "org.ccs.opendfl");
        AuditLogUtils.addAuditLog(request, userVo, "list", "ok", TIME_NULL);
        //找出Controller下的所有注解,以及频率限制、分布式锁配置参数
        List<RequestVo> list = AnnotationControllerUtils.getControllerRequests(pkg);
        List<RequestShowVo> showList = list.stream().map(RequestShowVo.class::cast).collect(Collectors.toList());

        //支持按requestUri查询接口
        if (StringUtils.isNotBlank(requestVo.getRequestUri())) {
            showList = showList.stream().filter(t -> t.getRequestUri().contains(requestVo.getRequestUri())).collect(Collectors.toList());
        }

        //显示从启动到现在各接口的调用情况(调用次数,调用时间超过1秒的最大时长,超限次数)
        requestRunCount(type, day, showList);
        return ResultData.success(showList);
    }

功能查询效果如下

 

 支持查近期的数据

每天以redis的zset存一份对每个有调用的接口调用次数,执行最大时长的记录 
系统用本地缓存记录调用次数,通过异步单线程每10秒同步一次到redis的zset

 

 核心代码

见:opendfl项目中的以下代码:
org.ccs.opendfl.core.utils.AnnotationControllerUtils.java
org.ccs.opendfl.core.utils.AnnotationClassUtils.java
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值