SpringBoot中Banner相关配置

Banner自定义网站

http://patorjk.com/software/taag
http://www.network-science.de/ascii/
http://www.degraeve.com/img2txt.php

Banner配置

在这里插入图片描述
可以定义一个banner.txt文件将自定义的复制粘贴进去,例如这样:
在这里插入图片描述
当然banner中不光可以定义这些图形,也可以定义版本号和图形的颜色和其他属性

${AnsiColor.BRIGHT_RED}//下方图形颜色
.____    ________  __________         ________        ____._____.___.
|    |   \_____  \ \____    /         \______ \      |    |\__  |   |
|    |    /  / \  \  /     /   ______  |    |  \     |    | /   |   |
|    |___/   \_/.  \/     /_  /_____/  |    `   \/\__|    | \____   |
|_______ \_____\ \_/_______ \         /_______  /\________| / ______|
        \/      \__>       \/                 \/            \/
MANIFEST.MF中的版本号
${application.version}
${application.formatted-version}
SpringBoot中的版本号
${spring-boot.version}
${spring-boot.formatted-version}

当然也可以不叫banner.txt,但是需要在application.properties配置文件中定义文件路径

spring.banner.location=classpath:banner1.txt

banner.txt中除了定义文字格式,还可以定义图片格式的banner

spring.banner.image.location=classpath:banner.png

关闭banner显示的三种方法

  • 代码关闭banner显示配置
public class Demo01Application {
    public static void main(String[] args) {  
        SpringApplication app = new SpringApplication(Demo01Application.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.run(args);
    }

}
  • application.properties配置文件
spring.main.banner-mode=off
  • 运行/调试配置
    在这里插入图片描述

SpringApplicationBannerPrinter关于Banner源码分析

在这里插入图片描述

	//拿到textBanner
	private Banner getTextBanner(Environment environment) {
		String location = environment.getProperty(BANNER_LOCATION_PROPERTY, DEFAULT_BANNER_LOCATION);
		Resource resource = this.resourceLoader.getResource(location);
		try {
			if (resource.exists() && !resource.getURL().toExternalForm().contains("liquibase-core")) {
				return new ResourceBanner(resource);
			}
		}
		catch (IOException ex) {
			// Ignore
		}
		return null;
	}
//拿到图片Banner
private Banner getImageBanner(Environment environment) {
		String location = environment.getProperty(BANNER_IMAGE_LOCATION_PROPERTY);
		if (StringUtils.hasLength(location)) {
			Resource resource = this.resourceLoader.getResource(location);
			return resource.exists() ? new ImageBanner(resource) : null;
		}
		for (String ext : IMAGE_EXTENSION) {
			Resource resource = this.resourceLoader.getResource("banner." + ext);
			if (resource.exists()) {
				return new ImageBanner(resource);
			}
		}
		return null;
	}

最后输出banner

@Override
		public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
			sourceClass = (sourceClass != null) ? sourceClass : this.sourceClass;
			this.banner.printBanner(environment, sourceClass, out);
		}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值