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

相关文章

深入浅出Spring中的@Autowired自动注入的工作原理及实践应用

《深入浅出Spring中的@Autowired自动注入的工作原理及实践应用》在Spring框架的学习旅程中,@Autowired无疑是一个高频出现却又让初学者头疼的注解,它看似简单,却蕴含着Sprin... 目录深入浅出Spring中的@Autowired:自动注入的奥秘什么是依赖注入?@Autowired

Spring 依赖注入与循环依赖总结

《Spring依赖注入与循环依赖总结》这篇文章给大家介绍Spring依赖注入与循环依赖总结篇,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Spring 三级缓存解决循环依赖1. 创建UserService原始对象2. 将原始对象包装成工

Java中如何正确的停掉线程

《Java中如何正确的停掉线程》Java通过interrupt()通知线程停止而非强制,确保线程自主处理中断,避免数据损坏,线程池的shutdown()等待任务完成,shutdownNow()强制中断... 目录为什么不强制停止为什么 Java 不提供强制停止线程的能力呢?如何用interrupt停止线程s

SpringBoot请求参数传递与接收示例详解

《SpringBoot请求参数传递与接收示例详解》本文给大家介绍SpringBoot请求参数传递与接收示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋... 目录I. 基础参数传递i.查询参数(Query Parameters)ii.路径参数(Path Va

SpringBoot路径映射配置的实现步骤

《SpringBoot路径映射配置的实现步骤》本文介绍了如何在SpringBoot项目中配置路径映射,使得除static目录外的资源可被访问,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一... 目录SpringBoot路径映射补:springboot 配置虚拟路径映射 @RequestMapp

Java MCP 的鉴权深度解析

《JavaMCP的鉴权深度解析》文章介绍JavaMCP鉴权的实现方式,指出客户端可通过queryString、header或env传递鉴权信息,服务器端支持工具单独鉴权、过滤器集中鉴权及启动时鉴权... 目录一、MCP Client 侧(负责传递,比较简单)(1)常见的 mcpServers json 配置

GSON框架下将百度天气JSON数据转JavaBean

《GSON框架下将百度天气JSON数据转JavaBean》这篇文章主要为大家详细介绍了如何在GSON框架下实现将百度天气JSON数据转JavaBean,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录前言一、百度天气jsON1、请求参数2、返回参数3、属性映射二、GSON属性映射实战1、类对象映

Java Stream 并行流简介、使用与注意事项小结

《JavaStream并行流简介、使用与注意事项小结》Java8并行流基于StreamAPI,利用多核CPU提升计算密集型任务效率,但需注意线程安全、顺序不确定及线程池管理,可通过自定义线程池与C... 目录1. 并行流简介​特点:​2. 并行流的简单使用​示例:并行流的基本使用​3. 配合自定义线程池​示

从原理到实战解析Java Stream 的并行流性能优化

《从原理到实战解析JavaStream的并行流性能优化》本文给大家介绍JavaStream的并行流性能优化:从原理到实战的全攻略,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的... 目录一、并行流的核心原理与适用场景二、性能优化的核心策略1. 合理设置并行度:打破默认阈值2. 避免装箱

解决升级JDK报错:module java.base does not“opens java.lang.reflect“to unnamed module问题

《解决升级JDK报错:modulejava.basedoesnot“opensjava.lang.reflect“tounnamedmodule问题》SpringBoot启动错误源于Jav... 目录问题描述原因分析解决方案总结问题描述启动sprintboot时报以下错误原因分析编程异js常是由Ja