Customizing the Banner

自定义方式

1.设置banner.txt文件  

默认读取根路径,也可以通过banner.location属性指定文件位置,并且可以通过banner.charset(默认是UTF-8)属性设置txt文件编码     

在banner.txt 中可以使用以下占位符
占位符 说明
${application.version} 在MANIFEST.MF中配置的应用程序的版本。例如Implementation-Version: 1.0  打印为 1.0
 ${application.formatted-version} NIFEST.MF中配置的应用程序的版本。格式化输出:前缀为v,然后括号包围。例如 (v1.0)
${spring-boot.version} 使用的springboot版本号。例如 Spring-Boot-Version: 1.5.9.RELEASE  打印为1.5.9.RELEASE 
${spring-boot.formatted-version} 使用的springboot版本号。格式化输出:前缀为v,然后括号包围。例如(v1.5.19.RELEASE)
${Ansi.NAME} (or ${AnsiColor.NAME}${AnsiBackground.NAME}${AnsiStyle.NAME}) 其中name是ansi转义码的名称,详情查看 AnsiPropertySource
${application.title} 在MANIFEST.MF中配置的应用程序的标题。例如Implementation-Title: MyApp 打印为 MyApp

2.设置banner.gif,banner.jpg,banner.png 图片文件 

默认读取根路径,也可以通过banner.location属性指定文件位置,并且可以通过banner.charset(默认是UTF-8)属性设置txt文件编码     

3.编程方式设置banner 

创建自定义banner类继承org.springframework.boot.Banner,    

package com.example.demo.banner;

import org.springframework.boot.Banner;
import org.springframework.core.env.Environment;

import java.io.PrintStream;
public class MyBanner implements Banner{
    @Override
    public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
        out.println("myBanner info");
    }
}

    在启动类设置banner

@SpringBootApplication
public class DemoApplication{
	public static void main(String[] args) {	 
        SpringApplication springApplication = new SpringApplication(DemoApplication.class);
        //设置自定义banner
        MyBanner myBanner = new MyBanner();
        springApplication.setBanner(myBanner);
        springApplication.run(args);

//      SpringApplication.run(DemoApplication.class, args);
	}

    备注:

  • 不管是TXT文件还是 .gif、.jpg、.png 图片文件,文件名都必须是banner(不区分大小写);
  • 优先级 1=2>3

猜你喜欢

转载自blog.csdn.net/yyqhwr/article/details/88121235