|
|
|
@ -989,68 +989,4 @@ metadata is provided per-instance rather than per-class. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[beans-scanning-index]] |
|
|
|
|
|
|
|
== Generating an Index of Candidate Components |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
While classpath scanning is very fast, it is possible to improve the startup performance |
|
|
|
|
|
|
|
of large applications by creating a static list of candidates at compilation time. In this |
|
|
|
|
|
|
|
mode, all modules that are targets of component scanning must use this mechanism. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOTE: Your existing `@ComponentScan` or `<context:component-scan/>` directives must remain |
|
|
|
|
|
|
|
unchanged to request the context to scan candidates in certain packages. When the |
|
|
|
|
|
|
|
`ApplicationContext` detects such an index, it automatically uses it rather than scanning |
|
|
|
|
|
|
|
the classpath. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
To generate the index, add an additional dependency to each module that contains |
|
|
|
|
|
|
|
components that are targets for component scan directives. The following example shows |
|
|
|
|
|
|
|
how to do so with Maven: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,xml,indent=0,subs="verbatim,quotes,attributes"] |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
<dependencies> |
|
|
|
|
|
|
|
<dependency> |
|
|
|
|
|
|
|
<groupId>org.springframework</groupId> |
|
|
|
|
|
|
|
<artifactId>spring-context-indexer</artifactId> |
|
|
|
|
|
|
|
<version>{spring-version}</version> |
|
|
|
|
|
|
|
<optional>true</optional> |
|
|
|
|
|
|
|
</dependency> |
|
|
|
|
|
|
|
</dependencies> |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
With Gradle 4.5 and earlier, the dependency should be declared in the `compileOnly` |
|
|
|
|
|
|
|
configuration, as shown in the following example: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,groovy,indent=0,subs="verbatim,quotes,attributes"] |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
dependencies { |
|
|
|
|
|
|
|
compileOnly "org.springframework:spring-context-indexer:{spring-version}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
With Gradle 4.6 and later, the dependency should be declared in the `annotationProcessor` |
|
|
|
|
|
|
|
configuration, as shown in the following example: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,groovy,indent=0,subs="verbatim,quotes,attributes"] |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
dependencies { |
|
|
|
|
|
|
|
annotationProcessor "org.springframework:spring-context-indexer:{spring-version}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The `spring-context-indexer` artifact generates a `META-INF/spring.components` file that |
|
|
|
|
|
|
|
is included in the jar file. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOTE: When working with this mode in your IDE, the `spring-context-indexer` must be |
|
|
|
|
|
|
|
registered as an annotation processor to make sure the index is up-to-date when |
|
|
|
|
|
|
|
candidate components are updated. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TIP: The index is enabled automatically when a `META-INF/spring.components` file is found |
|
|
|
|
|
|
|
on the classpath. If an index is partially available for some libraries (or use cases) |
|
|
|
|
|
|
|
but could not be built for the whole application, you can fall back to a regular classpath |
|
|
|
|
|
|
|
arrangement (as though no index were present at all) by setting `spring.index.ignore` to |
|
|
|
|
|
|
|
`true`, either as a JVM system property or via the |
|
|
|
|
|
|
|
xref:appendix.adoc#appendix-spring-properties[`SpringProperties`] mechanism. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|