当前位置: 首页 > news >正文

最好的网站建设长尾关键词爱站网

最好的网站建设,长尾关键词爱站网,文昌湖城乡建设局网站,网站建设招标信息需求: 要实现指定pkg(如com.qiqitrue.test.pojo)扫描包下所有class类信息:使用代码如下 使用的版本:0.10.2(截至目前是最新版)发现只能在idea编译期间可以获取得到(也就是在开发阶段…

需求:
要实现指定pkg(如com.qiqitrue.test.pojo)扫描包下所有class类信息:使用代码如下
pkg扫描包:如com.qiqitrue.test.pojo
使用的版本:0.10.2(截至目前是最新版)发现只能在idea编译期间可以获取得到(也就是在开发阶段)。当打成了jar包之后,获取不到。
先找到了
https://github.com/CESNET/perun/pull/3836
https://github.com/ronmamo/reflections
这个。改成了如下:

Reflections reflections = new Reflections(new ConfigurationBuilder().forPackage("com.my.project")// 先注释这个,一会说原因//.filterInputsBy(new FilterBuilder().includePackage("com.my.project")));

改了这个之后虽然能获取到。但实际上,所谓定义package,只是为classloader找路径而已。并没有指定传得包,也就是说,虽然我指定了package,但是,实际扫描得路径是target\classs(那范围可大了)。打成jar包之后获取,也是可以。貌似解决了。但如果我程序中有多次扫描不同的包下类上标注相同注解的类,那将会出现重叠的情况。
比如这样:

String pkg = "com.qiqitrue.pojo.a";//@1
Reflections reflections = new Reflections(pkg);
Set<Class<?>> resourceTypeClasses = reflections.getTypesAnnotatedWith(MyAnno.class);
log.info("扫描出类型{}资源类实体数:{}", subPathPackage, resourceTypeClasses.size());String pkg = "com.qiqitrue.pojo.b";//@2package com.qiqitrue.pojo.a;
@MyAnno
class A {
}package com.qiqitrue.pojo.b;
@MyAnno
class B {
}a和b包都有标注相同的注解情况下,那将产生重复。虽然能通过包名进行过滤,但是且不够优雅。

为了需要,就需要把filterInputsBy(new FilterBuilder().includePackage(“com.my.project”))这个也加上,发现就可以解决上面说的问题。

但是…打包jar之后运行,获取不到。最终解决是回退到版本:0.9.11
https://github.com/ronmamo/reflections/issues/373

虽然切换个版本就能解决,但是不知道为何解决了,继续刨根问底看一下,
对比两个版本的代码实现,发现0.10.X版本有了重大更新。跟踪源码
在这里插入图片描述
重点是scan()方法

protected Map<String, Map<String, Set<String>>> scan() {long start = System.currentTimeMillis();Map<String, Set<Map.Entry<String, String>>> collect = configuration.getScanners().stream().map(Scanner::index).distinct().collect(Collectors.toMap(s -> s, s -> Collections.synchronizedSet(new HashSet<>())));Set<URL> urls = configuration.getUrls();(configuration.isParallel() ? urls.stream().parallel() : urls.stream()).forEach(url -> {Vfs.Dir dir = null;try {dir = Vfs.fromURL(url);//@1 这是重点,进入这个方法看一下for (Vfs.File file : dir.getFiles()) {if (doFilter(file, configuration.getInputsFilter())) {ClassFile classFile = null;for (Scanner scanner : configuration.getScanners()) {try {if (doFilter(file, scanner::acceptsInput)) {List<Map.Entry<String, String>> entries = scanner.scan(file);if (entries == null) {if (classFile == null) classFile = getClassFile(file);entries = scanner.scan(classFile);}if (entries != null) collect.get(scanner.index()).addAll(entries);}} catch (Exception e) {if (log != null) log.trace("could not scan file {} with scanner {}", file.getRelativePath(), scanner.getClass().getSimpleName(), e);}}}}} catch (Exception e) {if (log != null) log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e);} finally {if (dir != null) dir.close();}});// mergeMap<String, Map<String, Set<String>>> storeMap =collect.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,entry -> entry.getValue().stream().filter(e -> e.getKey() != null).collect(Collectors.groupingBy(Map.Entry::getKey,HashMap::new,Collectors.mapping(Map.Entry::getValue, Collectors.toSet())))));if (log != null) {int keys = 0, values = 0;for (Map<String, Set<String>> map : storeMap.values()) {keys += map.size();values += map.values().stream().mapToLong(Set::size).sum();}log.info(format("Reflections took %d ms to scan %d urls, producing %d keys and %d values", System.currentTimeMillis() - start, urls.size(), keys, values));}return storeMap;
}

在这里插入图片描述
重点就是这个defaultUrlTypes。
在这里插入图片描述
在这里插入图片描述
主要涉及到了这个正则:
在这里插入图片描述
进行了取反,即不支持springboot打包jar的方式。

再看下0.9.11版本的
在这里插入图片描述
对比之下,就是没有新版取反的条件。

http://www.hkea.cn/news/10583/

相关文章:

  • ffmpeg做视频网站seo研究中心超逸seo
  • 锦州网站建设预订百度信息流开户多少钱
  • 网站开发费怎么做会计分录上海网站搜索排名优化哪家好
  • 网站免费模板资源爱站网关键词查询工具
  • 免费网站建设讯息百度搜索风云榜排名
  • 网站模板怎么用呢乐天seo视频教程
  • 中国建设银行总行官方网站外贸推广
  • 番禺的互联网公司衡阳网站优化公司
  • 自己买服务器做网站百度app手机版
  • wordpress插件团购蜘蛛seo超级外链工具
  • 怎么设置微信公众号seo关键词找29火星软件
  • 有哪些网站可以做问卷调查推广赚钱的软件
  • 网上做批发的网站seo实战指导
  • 淮安营销型网站建设最好的网站优化公司
  • 江苏兴力建设集团有限公司网站网络营销策划方案范文
  • 代做网站修改维护广告推广的软件
  • 徐州模板建站系统百度资源搜索平台官网
  • 哪些软件可以做网站线下推广100种方式
  • 高品质网站开发搜索热词排名
  • 平台式网站模板下载地址seo营销策划
  • 深圳网站论坛建设淘宝引流推广怎么做
  • 杭州模板网站建设腾讯云域名
  • 东软 网站群平台建设足球排名世界排名
  • 外贸企业公司网站建设十大培训机构教育培训机构哪家好
  • 橙子官方网站济源网络推广
  • 制作网站报价成都百度网站排名优化
  • 网站如何做超链接广州seo黑帽培训
  • typecho 和WordPress站长工具seo综合查询是什么
  • 有没有专业做特产的网站seo发帖工具
  • 登封建设局网站广告营销推广方案