ApiService { @Transactional(rollbackFor = Exception.class) @Async public void scanApi() { synchronized (this){ if(!scanComplete.get()){ throw new ServiceRuntimeException("扫描未完成，请稍后重试"); } scanComplete.set(false); } AtomicInteger addPoint = new AtomicInteger(); AtomicInteger updatePoint = new AtomicInteger(); log.info("开始扫描api列表"); for(String s: discoveryClient.getServices()){ List<ServiceInstance> serviceInstances = discoveryClient.getInstances(s); ServiceInstance instance = serviceInstances.get(0); log.debug("获取到服务：{}",s); URL url1; try { String sUrl = instance.getUri() + "/v2/api-docs"; url1 = new URL(sUrl); url1.openStream(); OpenAPI openAPI = new OpenAPIV3Parser().read(sUrl); log.debug("获取到API信息，开始处理........."); openAPI.getPaths().keySet().forEach(url -> { PathItem path = openAPI.getPaths().get(url); doMethod(addPoint, updatePoint, instance, url, path.getGet(), "GET"); doMethod(addPoint, updatePoint, instance, url, path.getPut(), "PUT"); doMethod(addPoint, updatePoint, instance, url, path.getPost(), "POST"); doMethod(addPoint, updatePoint, instance, url, path.getDelete(), "DELETE"); doMethod(addPoint, updatePoint, instance, url, path.getOptions(), "OPTIONS"); doMethod(addPoint, updatePoint, instance, url, path.getHead(), "HEAD"); doMethod(addPoint, updatePoint, instance, url, path.getPatch(), "PATCH"); doMethod(addPoint, updatePoint, instance, url, path.getTrace(), "TRACE"); }); } catch (Exception e1) { log.debug("未发现api-docs，跳过,message:{}",e1.getMessage()); } } log.debug(">>> 新增权限点{}个，更新权限点{}个",addPoint.get(),updatePoint.get()); scanComplete.set(true); }  @Transactional(rollbackFor = Exception.class) @Async void scanApi(); Pagination<SysApi> getDataTables(Integer pageNum, Integer pageSize, List<String> tagList, List<String> serviceIdList); List<SysApi> selectByUuid(String uuid); List<SysApi> selectByMenuId(Integer menuId); List<SysApi> selectAll(); SysApi selectByPk(Integer permissionId); SysApi getApi(Integer integer); List<SysApi> getApis(List<Integer> ids);  }
@Test @Transactional public void scanApi() { apiService.scanApi(); }