已签名的Jar文件中的Spring Component Scan(@Autowire)很慢 [英] Spring Component Scan (@Autowire) in signed Jar Files is slow

查看:362
本文介绍了已签名的Jar文件中的Spring Component Scan(@Autowire)很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年前我们遇到了独立java应用程序中Spring组件扫描速度慢的问题所以我在stackoverflow中问过:
慢速弹簧组件扫描
。多年以后我再次​​偶然发现了这个问题,我想我发现它为什么很慢:这是因为jar文件是签名的。
目前我们的应用程序中有大约170个jar文件。我们自己和第三方。我们签下所有人。
通常我们使用webstart,组件扫描的性能还可以。
通过执行java -cp mainclass开始我们的应用程序使用巨大的类路径,compoennt扫描需要几分钟。
如果我只是从所有jar文件中删除MANIFEST.MF文件(只包含签名信息),再次运行应用程序,速度就像webstart一样快。
因此,签名检查似乎耗费了大量的时间。
我尝试在Java控制台中停用签名扫描。没有效果。仍然很慢。是否存在java运行时参数?

Years ago we had a problem with slow Spring component scans in standalone java applications so I asked in stackoverflow: Slow spring component scan . Years later I stumbled again about this problem and I think I found out why it is slow: It is because the jar files are signed. Currently we have about 170 jar files in our app. Our own and 3rd party. We sign all of them. Usually we use webstart and the performance for the component scan is ok. Starting our app with a huge classpath by just doing "java -cp mainclass" the compoennt scan takes minutes. If I just remove the MANIFEST.MF files from all jar files (which only contain the signing info), and run the application again the speed is fast as webstart. So it seems the signature check costs an awewful lot of time. I tried do deactivate Signature Scan in the Java console. No effect. Still slow. Are there java runtime parameters?

推荐答案

解决方案是使用spring-context-indexer创建候选组件索引。将Spring-context-indexer添加为Gradle中的compileOnly依赖项,或将其注册为IDE中的注释处理器。

The solution is to create a candidate component index using spring-context-indexer. Add the spring-context-indexer as a compileOnly dependency in Gradle or register it as an annotation processor in your IDE.

请参阅文档

这将在jar的META-INF目录中创建一个名为spring.components的文件。 Spring会自动使用这个组件列表,而不是扫描整个jar的每个类。

This will create a file called spring.components in the META-INF directory of your jar. Spring will automatically use this list of components instead of scanning every class of the entire jar.

这篇关于已签名的Jar文件中的Spring Component Scan(@Autowire)很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆