Spring Boot:自定义和禁用banner


#Spring Boot#


banner 是什么?

创建 spring boot 项目,编写主类:

package demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

运行结果:

如何修改banner ?

src/main/resources/中增加banner.txt,加入字符图案 Hello World

重新运行 DemoApplication ,输出:

如何生成字符图案

http://patorjk.com/software/taag

http://www.network-science.de/ascii

http://www.degraeve.com/img2txt.php

如何增加版本号

在 banner.txt 中合适的地方增加下面的内容即可:

${spring-boot.version}

如何定制颜色

支持,不保证兼容性,没有必要。

如何禁用Banner

方法1:改代码

SpringApplication app = new SpringApplication(DemoApplication.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);

方法2:改配置src/main/resources/application.properties

spring.main.banner-mode=off

( 本文完 )