Skip to content

Commit f128feb

Browse files
committed
Document candidates index mechanism
Issue: SPR-14711
1 parent 2fe3108 commit f128feb

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/asciidoc/core-beans.adoc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5861,6 +5861,54 @@ metadata is provided per-instance rather than per-class.
58615861

58625862

58635863

5864+
[[beans-scanning-index]]
5865+
=== Generating a index of candidate components
5866+
Rather than scanning the classpath to find components, it is also possible to generate an
5867+
index at compilation time. When the `ApplicationContext` detects such index it will
5868+
automatically use it rather than scanning the classpath. This can reduce the time required
5869+
to refresh the `ApplicationContext` as scanning large applications can take a significant
5870+
amount of time.
5871+
5872+
To generate the index, simply add an additional dependency to each module that contains
5873+
components that are target for component scan directives:
5874+
5875+
[source,xml,indent=0]
5876+
[subs="verbatim,quotes,attributes"]
5877+
----
5878+
<dependencies>
5879+
<dependency>
5880+
<groupId>org.springframework</groupId>
5881+
<artifactId>spring-context-indexer</artifactId>
5882+
<version>{spring-version}</version>
5883+
<optional>true</optional>
5884+
</dependency>
5885+
</dependencies>
5886+
----
5887+
5888+
Or, using Gradle:
5889+
5890+
[source,groovy,indent=0]
5891+
[subs="verbatim,quotes,attributes"]
5892+
----
5893+
dependencies {
5894+
compileOnly("org.springframework:spring-context-indexed:{spring-version}")
5895+
}
5896+
----
5897+
5898+
That process will generate a `META-INF/spring.components` file that is going to be
5899+
included in the jar.
5900+
5901+
[TIP]
5902+
====
5903+
The index is enabled automatically when a `META-INF/spring.components` is found on the
5904+
classpath. If an index is partially available for some libraries (or use cases) but
5905+
couldn't be built for the whole application, you can fallback to a regular classpath
5906+
arrangement (i.e. as no index was present at all) by setting `spring.index.ignore` to
5907+
`true`, either as a system property or in a `spring.properties` file at the root of the
5908+
classpath.
5909+
====
5910+
5911+
58645912

58655913
[[beans-standard-annotations]]
58665914
== Using JSR 330 Standard Annotations

0 commit comments

Comments
 (0)