DisableSpringBootBanneratStartup

编程

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:

1

spring.main.banner-mode=off

Or if we are using application.yaml:

1

2

3

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:

1

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:

1

2

3

new

SpringApplicationBuilder(MyApplication.

class

)

    

.bannerMode(Banner.Mode.OFF)

    

.run(args)

And when using SpringApplication:

1

2

3

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:

1

spring.banner.location=classpath:/banner.txt

Or, if we"re using YAML:

1

2

3

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.

以上是 DisableSpringBootBanneratStartup 的全部内容, 来源链接: utcz.com/z/513020.html

回到顶部