簡體   English   中英

如何創建 Spring 5 組件索引?

[英]How can I create a Spring 5 component index?

Spring Framework 5 顯然包含對位於 META-INF/spring.components 中的“組件索引”的支持,可用於避免類路徑掃描的需要,因此,我認為,可以改善 web 應用程序的啟動時間。

看:

如何為我計划升級到 Spring 5 的現有 Web 應用程序創建這樣的組件索引?

(理想情況下,它會在我想象的 Maven 構建時自動生成,但任何其他可行的方法至少會給我一個工作起點)

Spring 5增加了一個新特性來提高大型應用程序的啟動性能。

它在編譯時創建一個候選組件列表。

在這種模式下,應用程序的所有模塊都必須使用這種機制,因為當 ApplicationContext 檢測到此類索引時,它會自動使用它而不是掃描類路徑。

要生成索引,我們只需要為每個模塊添加以下依賴項

馬文:

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-indexer</artifactId>
        <version>5.0.3.RELEASE</version>
        <optional>true</optional>
    </dependency>
</dependencies>

搖籃

dependencies {
    compileOnly("org.springframework:spring-context-indexer:5.0.3.RELEASE")
}

此過程將生成一個META-INF/spring.components文件,該文件將包含在 jar 中。

參考: 1.10.9。 生成候選組件的索引

META-INF/spring.components文件由名為spring-context-indexer的注釋處理器庫生成。 如果將此庫作為“注釋處理器路徑”添加到 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>

此設置需要 maven-compiler-plugin 3.5 或更高版本。

另見: https : //maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationProcessorPaths

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM