SpringBoot(四):banner的控制

banner在springboot中是一个支持可配(banner的样式,banner的颜色,banner的内容)、是否显示。

1)banner显示内容配置:

默认springboot如果在src/resources下包含这样的一个banner信息,则会使用该banner.txt内容替换spring boot默认的banner信息:

${AnsiColor.BRIGHT_YELLOW}
                   ${AnsiColor.BRIGHT_RED}_ooOoo_${AnsiColor.BRIGHT_YELLOW}
                  ${AnsiColor.BRIGHT_RED}o8888888o${AnsiColor.BRIGHT_YELLOW}
                  ${AnsiColor.BRIGHT_RED}88${AnsiColor.BRIGHT_YELLOW}" . "${AnsiColor.BRIGHT_RED}88${AnsiColor.BRIGHT_YELLOW}
                  (| -_- |)
                  O  =  /O
               ____/`---'\____
             .'  \|     |//  `.
            /  \|||  :  |||//  
           /  _||||| -:- |||||-  
           |   | \  -  /// |   |
           | \_|  ''---/''  |   |
             .-\__  `-`  ___/-. /
         ___`. .'  /--.--  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;` _ /`;.`/ - ` : | |
        `-.   \_ __ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG

备注:

1)其中banner.txt内容的中第一行信息,用来配置banner.txt的文字颜色;

2)其中被颜色样式包含的banner内容是对banner个别信息颜色的修改。

2)banner是否显示配置方式:

方式1)通过src/resources/applicatioin.properties配置:

# 可选值:console.off.log
spring.main.banner-mode=off

方式2)通过启动入口函数配置:

package app;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;

import java.util.Arrays;

@ComponentScan("com.dx.controller")
@EnableAutoConfiguration
public class App {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(args));
        // 启动方式一:
//        SpringApplication.run(App.class, args);

        // 启动方式二:
//        SpringApplication springApplication = new SpringApplication(App.class);
//        springApplication.setBannerMode(Banner.Mode.OFF);
//        springApplication.run(args);

        // 启动方式三:
        new SpringApplicationBuilder(App.class)
                .bannerMode(Banner.Mode.OFF)
                .build()
                .run(args);
    }
}
原文地址:https://www.cnblogs.com/yy3b2007com/p/8734617.html