Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
SpringApplication provides numerous hooks for customizing how your application starts, what it displays, how it listens for connections, and how it participates in a servlet container. This guide covers the most common application-level customizations with concrete steps for each.
Customize or disable the startup banner
By default, Spring Boot prints an ASCII art banner when the application starts. To replace it, add abanner.txt file to the root of your classpath (src/main/resources/banner.txt). The file supports the following variables:
| Variable | Description |
|---|---|
${application.version} | Version declared in MANIFEST.MF |
${application.formatted-version} | Version formatted as (v1.0) |
${spring-boot.version} | Spring Boot version |
${spring-boot.formatted-version} | Spring Boot version formatted |
banner-mode property to off:
Access application arguments programmatically
To access the raw arguments passed on the command line, injectApplicationArguments into any bean:
ApplicationArguments distinguishes between option arguments (those starting with --) and non-option arguments, and gives you access to both.
Use Spring application event hooks
Spring Boot publishes several application events before and after theApplicationContext is created. To listen for them, register an ApplicationListener:
ApplicationStartingEvent → ApplicationEnvironmentPreparedEvent → ApplicationContextInitializedEvent → ApplicationPreparedEvent → ApplicationStartedEvent → ApplicationReadyEvent.
Some events are published before the
ApplicationContext is created, so you cannot register listeners for them as @Bean definitions. Register them with SpringApplication.addListeners(...) or via META-INF/spring.factories instead.Environment or ApplicationContext before refresh, implement EnvironmentPostProcessor and register it in META-INF/spring.factories:
Enable lazy initialization
To defer bean creation until first use, enable lazy initialization globally:Run on a different port
To change the HTTP port the embedded server listens on:Enable virtual threads
To enable Java 21 virtual threads (Project Loom), set the following property:@Async executor to use virtual threads automatically.
Virtual threads require Java 21 or later. Verify your build is targeting Java 21 (
--release 21) and that your JDK supports them before enabling this option.Use SpringApplicationBuilder for a parent context
To create a parent/childApplicationContext hierarchy — for example, to share beans between multiple child contexts — use SpringApplicationBuilder:
Troubleshoot auto-configuration
When Spring Boot’s auto-configuration produces unexpected results, enableDEBUG logging to see the auto-configuration decision report:
application.properties:
/actuator/conditions endpoint renders the same report as JSON for a running application.
When reading auto-configuration classes, pay attention to:
@ConditionalOnMissingBean— the auto-configuration backs off when you define your own bean.@ConditionalOnClass— the auto-configuration only activates when a specific class is on the classpath.@ConfigurationProperties— identifies the external properties that control the auto-configuration behavior.
Create a custom FailureAnalyzer
To intercept a startup exception and produce a human-readable message, extendAbstractFailureAnalyzer:
META-INF/spring.factories:
Deploy as a traditional WAR file
To deploy to an external servlet container instead of the embedded one, extendSpringBootServletInitializer and override configure:
Extend SpringBootServletInitializer
Modify your main application class (or create a separate one) to extend
SpringBootServletInitializer:Change the packaging to WAR
In
pom.xml, set the packaging to war and mark the embedded container as provided: