Customizing the Banner自定义SpringBoot的启动banner

2024-02-03 20:20

本文主要是介绍Customizing the Banner自定义SpringBoot的启动banner,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

先看一下官方文档是怎么写的

23.2 Customizing the Banner

The banner that is printed on start up can be changed by adding a banner.txt file to your classpath or by setting the spring.banner.location property to the location of such a file. If the file has an encoding other than UTF-8, you can set spring.banner.charset. In addition to a text file, you can also add a banner.gifbanner.jpg, or banner.png image file to your classpath or set the spring.banner.image.location property. Images are converted into an ASCII art representation and printed above any text banner.

自定义banner

banner它就是在启动的时候可以通过添加在你的类路径的banner.txt或者是spring.banner.location属性指定的的文件来改变。如果你的文件不是utf-8的其他字符类型,你需要设置

spring.banner.charset的属性。除了文本文件,你也可以添加banner.gif,banner.jpg或者是banner.png图片文件在你的类路径下或者是指定spring.banner.image.location的属性,

images的文件将会转换为ASCall艺术形式打印在textbanner上。

Inside your banner.txt file, you can use any of the following placeholders:

Table 23.1. Banner variables

VariableDescription

${application.version}

The version number of your application, as declared in MANIFEST.MF. For example,Implementation-Version: 1.0 is printed as 1.0.

${application.formatted-version}

The version number of your application, as declared in MANIFEST.MF and formatted for display (surrounded with brackets and prefixed with v). For example (v1.0).

${spring-boot.version}

The Spring Boot version that you are using. For example 2.1.1.RELEASE.

${spring-boot.formatted-version}

The Spring Boot version that you are using, formatted for display (surrounded with brackets and prefixed with v). For example (v2.1.1.RELEASE).

${Ansi.NAME} (or ${AnsiColor.NAME}${AnsiBackground.NAME}${AnsiStyle.NAME})

Where NAME is the name of an ANSI escape code. See AnsiPropertySource for details.

${application.title}

The title of your application, as declared in MANIFEST.MF. For exampleImplementation-Title: MyApp is printed as MyApp.

在你的banner.txt的文件中,你可以使用下面的占位符

${application.version} 这个是你应用的版本号,这个定义在MANIFEST.MF。例如,Implementation-Version:1.0将会打印的是1.0

${application.formatted-version}这个也是你应用的版本号,这个版本号再MANINEST.MF的文件中,并且格式化显示(用括号和前缀v).例如(v1.0)

${spring-boot.version} spring的版本号

${spring-boot.formatted-version} springBoot版本号的格式化显示

等。。。。。

 

来源: https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#using-boot-devtools-remote

The SpringApplication.setBanner(…) method can be used if you want to generate a banner programmatically. Use the org.springframework.boot.Banner interface and implement your own printBanner() method.

SpringApplication.setBanner(。。)是当你想生成banner的方法时使用,使用org.springframework.boot.Banner的接口和实现你自己printBanner()的方法使用

就翻译到这里吧,下面的页没有太理解就不翻译了,然后我们开始自定义启动程序是在log中打印的banner

第一步、在Spring-Boot的项目中resource的文件下建一个banner.txt 编码格式是utf-8形式的(不要管banner.jpg,只需建一个banner.txt文件就可以,banner.jpg是用来测试启动图片的一会

儿会讲)

我在看其他的文档上的时候,推荐了一个网站可以使你的字符已各种样式来展示,你只需填写你要打印的字符,然后复制下来放到banner.txt中就可以

http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20

这个就是生成字符的网址

然后重启启动的时候就会出现了

如果像我同时指定了俩个文件,它会出现一个什么样的结果呢?看一下下面的这张图

他会把banner.jpg和banner.txt中的所有内容都会加载到console的窗口中,如果你想指定一个的话,需要使用上面说的属性

 

 

 

 

 

这篇关于Customizing the Banner自定义SpringBoot的启动banner的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/675290

相关文章

Java图片压缩三种高效压缩方案详细解析

《Java图片压缩三种高效压缩方案详细解析》图片压缩通常涉及减少图片的尺寸缩放、调整图片的质量(针对JPEG、PNG等)、使用特定的算法来减少图片的数据量等,:本文主要介绍Java图片压缩三种高效... 目录一、基于OpenCV的智能尺寸压缩技术亮点:适用场景:二、JPEG质量参数压缩关键技术:压缩效果对比

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

Java利用docx4j+Freemarker生成word文档

《Java利用docx4j+Freemarker生成word文档》这篇文章主要为大家详细介绍了Java如何利用docx4j+Freemarker生成word文档,文中的示例代码讲解详细,感兴趣的小伙伴... 目录技术方案maven依赖创建模板文件实现代码技术方案Java 1.8 + docx4j + Fr

SpringBoot首笔交易慢问题排查与优化方案

《SpringBoot首笔交易慢问题排查与优化方案》在我们的微服务项目中,遇到这样的问题:应用启动后,第一笔交易响应耗时高达4、5秒,而后续请求均能在毫秒级完成,这不仅触发监控告警,也极大影响了用户体... 目录问题背景排查步骤1. 日志分析2. 性能工具定位优化方案:提前预热各种资源1. Flowable

基于SpringBoot+Mybatis实现Mysql分表

《基于SpringBoot+Mybatis实现Mysql分表》这篇文章主要为大家详细介绍了基于SpringBoot+Mybatis实现Mysql分表的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录基本思路定义注解创建ThreadLocal创建拦截器业务处理基本思路1.根据创建时间字段按年进

Java编译生成多个.class文件的原理和作用

《Java编译生成多个.class文件的原理和作用》作为一名经验丰富的开发者,在Java项目中执行编译后,可能会发现一个.java源文件有时会产生多个.class文件,从技术实现层面详细剖析这一现象... 目录一、内部类机制与.class文件生成成员内部类(常规内部类)局部内部类(方法内部类)匿名内部类二、

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Springboot @Autowired和@Resource的区别解析

《Springboot@Autowired和@Resource的区别解析》@Resource是JDK提供的注解,只是Spring在实现上提供了这个注解的功能支持,本文给大家介绍Springboot@... 目录【一】定义【1】@Autowired【2】@Resource【二】区别【1】包含的属性不同【2】@

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La