[英]How can I create a Spring 5 component index?
Spring Framework 5 apparently contains support for a "component index" which lives in META-INF/spring.components and can be used to avoid the need for class-path scanning, and thus, I assume, improve a webapps' startup time. Spring Framework 5 显然包含对位于 META-INF/spring.components 中的“组件索引”的支持,可用于避免类路径扫描的需要,因此,我认为,可以改善 web 应用程序的启动时间。
See:看:
How can I create such a component index for an existing web app I plan to upgrade to Spring 5?如何为我计划升级到 Spring 5 的现有 Web 应用程序创建这样的组件索引?
(Ideally it would get generated automatically at build time with Maven I imagine, but any other workable approaches would at least give me a starting point to work from) (理想情况下,它会在我想象的 Maven 构建时自动生成,但任何其他可行的方法至少会给我一个工作起点)
Spring 5 Has added a new feature to improve startup performance of large applications. Spring 5增加了一个新特性来提高大型应用程序的启动性能。
it creates a list of component candidates at compilation time.它在编译时创建一个候选组件列表。
In this mode, all modules of the application must use this mechanism as, when the ApplicationContext detects such index, it will automatically use it rather than scanning the classpath.在这种模式下,应用程序的所有模块都必须使用这种机制,因为当 ApplicationContext 检测到此类索引时,它会自动使用它而不是扫描类路径。
To generate the index, we just need to add below dependency to each module要生成索引,我们只需要为每个模块添加以下依赖项
Maven:马文:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<version>5.0.3.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
Gradle摇篮
dependencies {
compileOnly("org.springframework:spring-context-indexer:5.0.3.RELEASE")
}
This process will generate a META-INF/spring.components file that is going to be included in the jar.此过程将生成一个META-INF/spring.components文件,该文件将包含在 jar 中。
Reference : 1.10.9.参考: 1.10.9。 Generating an index of candidate components 生成候选组件的索引
The META-INF/spring.components
files are generated by an annotation processor library called spring-context-indexer
. META-INF/spring.components
文件由名为spring-context-indexer
的注释处理器库生成。 If you add this library as "annotation processor path" to the maven-compiler-plugin, the files will be generated automatically at build time:如果将此库作为“注释处理器路径”添加到 maven-compiler-plugin,文件将在构建时自动生成:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<version>5.0.6.RELEASE</version>
</path>
</annotationProcessorPaths>
...
</configuration>
</plugin>
This setup requires maven-compiler-plugin version 3.5 or greater.此设置需要 maven-compiler-plugin 3.5 或更高版本。
See also: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationProcessorPaths另见: https : //maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationProcessorPaths
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.