如何创建Spring 5组件索引? [英] How can I create a Spring 5 component index?

查看:1043
本文介绍了如何创建Spring 5组件索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring Framework 5显然包含对组件索引的支持,它存在于META-INF / spring.components中,可用于避免类路径扫描的需要,因此,我认为,改进了webapps的启动时间。

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.

参见:

  • The "what's new in spring 5" mention
  • The jira issue under which the support was developed
  • Some examples of what the spring.components format seems to be from the change implementing it

如何创建这样的组件索引对于现有的Web应用程序,我打算升级到Spring 5?

How can I create such a component index for an existing web app I plan to upgrade to Spring 5?

(理想情况下,它会在我想象的Maven构建时自动生成,但任何其他可行的方法至少会给我一个工作的起点)

(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)

推荐答案

Spring 5 添加了一项新功能,以提高大型应用程序的启动性能。

Spring 5 Has added a new feature to improve startup performance of large applications.

它在编译时创建一个候选组件列表。

在此模式下,应用程序的所有模块都必须使用此机制作为,当ApplicationContext检测到这样的索引时,它会自动使用它而不是扫描类路径。

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.

要生成索引,我们只需要在每个模块中添加以下依赖关系

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")
}

此过程将生成一个 META-INF / spring.components 文件,该文件将包含在jar中。

This process will generate a META-INF/spring.components file that is going to be included in the jar.

参考: 1.10.9。生成候选组件的索引

这篇关于如何创建Spring 5组件索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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