1. Introduction
Spring Boot is a great way to create Java web applications, but some of its default behavior may not be ideal for everyone.
One particular feature is the Spring Boot banner that gets printed at startup:
While this banner is typically harmless, in some cases it may be desirable to disable it. For example, to prevent errors with custom logging configurations or save bandwidth with remote log aggregation systems.
In this tutorial, we will look at some different ways to disable the Spring Boot banner at startup.
2. Using Configuration
Using configuration is the most flexible way to disable the startup banner. It requires no code changes and can easily be reverted if needed.
We can disable the startup banner using application.properties:
spring.main.banner-mode=off
Or if we are using application.yaml:
spring:
main:
banner-mode: "off"
And finally, thanks to Spring Boot’s externalized configuration support, we can also disable it by setting an environment variable:
SPRING_MAIN_BANNER-MODE=off
3. Using Code
In addition to configuration, there are also multiple ways to disable the Spring Boot banner using code. The downside to using code is that we need to do this for each application, and it requires a code change to revert.
When using the SpringApplicationBuilder:
new SpringApplicationBuilder(MyApplication.class)
.bannerMode(Banner.Mode.OFF)
.run(args)
And when using SpringApplication:
SpringApplication app = new SpringApplication(MyApplication.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
4. Using IDE
Most modern IDEs include a way to disable the Spring Boot banner without needing configuration or code.
IntelliJ offers a checkbox for Spring Boot run configurations that will disable the banner:
5. Change Banner Text
Another way to disable the Spring Boot startup banner is to change the banner text to an empty file.
We first specify a custom file in application.properties:
spring.banner.location=classpath:/banner.txt
Or, if we’re using YAML:
spring:
banner:
location: classpath:/banner.txt
Then we create a new empty file in src/main/resources named banner.txt.
6. Conclusion
In this tutorial, we’ve seen various ways to disable the Spring Boot banner, using a combination of configuration or code.