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);
}