Provide a configuration option to enable lazy initialization
Closes gh-15870
This commit is contained in:
@@ -125,6 +125,7 @@ content into your application. Rather, pick only the properties that you need.
|
||||
# APPLICATION SETTINGS ({sc-spring-boot}/SpringApplication.{sc-ext}[SpringApplication])
|
||||
spring.main.allow-bean-definition-overriding=false # Whether bean definition overriding, by registering a definition with the same name as an existing definition, is allowed.
|
||||
spring.main.banner-mode=console # Mode used to display the banner when the application runs.
|
||||
spring.main.lazy-initialization=false # Whether initialization should be performed lazily.
|
||||
spring.main.sources= # Sources (class names, package names, or XML resource locations) to include in the ApplicationContext.
|
||||
spring.main.web-application-type= # Flag to explicitly request a specific type of web application. If not set, auto-detected based on the classpath.
|
||||
|
||||
|
||||
@@ -91,6 +91,36 @@ the `debug` property as follows:
|
||||
|
||||
|
||||
|
||||
[[boot-features-lazy-initialization]]
|
||||
=== Lazy Initialization
|
||||
`SpringApplication` allows an application to be initialized lazily. When lazy
|
||||
initialization is enabled, beans are created as they are needed rather than during
|
||||
application startup. As a result, enabling lazy initialization can reduce the time that
|
||||
it takes your application to start. In a web application, enabling lazy initialization
|
||||
will result in many web-related beans not being initialized until an HTTP request is
|
||||
received.
|
||||
|
||||
A downside of lazy initialization is that it can delay the discovery of a problem with
|
||||
the application. If a misconfigured bean is initialized lazily, a failure will no longer
|
||||
occur during startup and the problem will only become apparent when the bean is
|
||||
initialized. Care must also be taken to ensure that the JVM has sufficient memory to
|
||||
accommodate all of the application's beans and not just those that are initialized during
|
||||
startup. For these reasons, lazy initialization is not enabled by default and it is
|
||||
recommended that fine-tuning of the JVM's heap size is done before enabling lazy
|
||||
initialization.
|
||||
|
||||
Lazy initialization can be enabled programatically using the `lazyInitialization` method
|
||||
on `SpringApplicationBuilder` or the `setLazyInitialization` method on
|
||||
`SpringApplication`. Alternatively, it can be enabled using the
|
||||
`spring.main.lazy-initialization` property as shown in the following example:
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
spring.main.lazy-initialization=true
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[boot-features-banner]]
|
||||
=== Customizing the Banner
|
||||
The banner that is printed on start up can be changed by adding a `banner.txt` file to
|
||||
|
||||
Reference in New Issue
Block a user