万年不变,如图所示 ^ ^
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)
2020-06-28 13:07:33.360 INFO 17272 --- [ restartedMain] com.example.demo.Application : Starting Application on DELL with PID 17272 (C:\study\com.inherit.text\target\classes started by Opensky in C:\study\com.inherit.text)
2020-06-28 13:07:33.364 INFO 17272 --- [ restartedMain] com.example.demo.Application : No active profile set, falling back to default profiles: default
2020-06-28 13:07:33.447 INFO 17272 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
接下来,咱们换换耶
springBoot 有一个接口 org.springframework.boot.Banner 是专门来做这个操作的。
实现这个接口来自定义打印 Banner 信息。
org.springframework.boot.ResourceBanner
文本格式
SpringBoot 会读取配置项banner.txt和banner.location,从配置项中获取真实的文件地址;如果配置中没有配置,会把配置项作为文件去加载;
org.springframework.boot.ImageBanner
图片格式
SpringBoot 加载配置项banner.image.location,从配置项中获取真实的路径,SpringBoot 会根据配置项的路径加载文件。
如果没有配置banner.image.location,转而依次加载banner.gif、banner.jpg、 banner.png这三个中存在的文件;
如果上面两种都没有配置,SpringBoot 就会加载默认的 Banner;也就是文章开头介绍的方式。
例:文本格式(ResourceBanner)
环境:
操作系统:Win10
SpringBoot版本:v2.3.0.RELEASE
创建启动类:
> src/main/java/{package}/Application.java
package com.example.demo;
import org.springframework.boot.Banner;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.SpringVersion;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
// 启动颜色格式化
// 这不是唯一启动颜色格式的方式,有兴趣的同学可以查看源码
/**
* 1. AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS);
* 2. 在`src/main/resources`目录下新建文件`application.properties`,
* 内容为:`spring.output.ansi.enabled=always`
*
* 重要:如果配置第二种方式,第一种方式就不会起作用
*/
AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS);
new SpringApplicationBuilder(Application.class)//
.main(SpringVersion.class) // 这个是为了可以加载 Spring 版本
.bannerMode(Banner.Mode.CONSOLE)// 控制台打印
.run(args);
}
}
创建Banner文件
src/main/resource/banner.txt
${AnsiColor.BRIGHT_YELLOW}
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
${AnsiColor.BRIGHT_RED}
Application Version: ${application.version}${application.formatted-version}
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}
-
${AnsiColor.BRIGHT_RED}:设置控制台中输出内容的颜色,可以自定义,具体参考
org.springframework.boot.ansi.AnsiColor
-
${application.version}:用来获取MANIFEST.MF文件中的版本号,这就是为什么要在Application.java中指定SpringVersion.class
-
{application.formatted-version}:格式化后的{application.version}版本信息
-
${spring-boot.version}:Spring Boot的版本号
-
{spring-boot.formatted-version}:格式化后的{spring-boot.version}版本信息
效果