1、创建文件
1.1 创建banner.txt
文件
在项目的src/main/resources
目录下创建一个名为banner.txt
的文件。
1.2 简单banner.txt
示例:
===============================
我的项目名- Spring Boot Application
Version: ${spring-boot.version}
${application.version}
===============================
spring-boot.version
是Spring Boot的版本号,application.version
通常在pom.xml
或build.gradle
文件中定义。
1.3 艺术banner.txt
如果你想要一个更复杂的横幅,你可以使用ASCII艺术生成器来创建,然后将其粘贴到banner.txt文件中。
可使用:Spring Boot自定义启动Banner在线生成工具网站
示例:
█████████ ███ █████ █████
███▒▒▒▒▒███ ▒▒▒ ▒▒███ ▒▒███
▒███ ▒▒▒ ████████ ████████ ████ ████████ ███████ ▒███████ ██████ ██████ ███████
▒▒█████████ ▒▒███▒▒███▒▒███▒▒███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒███▒▒███ ███▒▒███ ███▒▒███▒▒▒███▒
▒▒▒▒▒▒▒▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███▒███ ▒███▒███ ▒███ ▒███
███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███▒███ ▒███▒███ ▒███ ▒███ ███
▒▒█████████ ▒███████ █████ █████ ████ █████▒▒███████ ████████ ▒▒██████ ▒▒██████ ▒▒█████
▒▒▒▒▒▒▒▒▒ ▒███▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒
▒███ ███ ▒███
█████ ▒▒██████
▒▒▒▒▒ ▒▒▒▒▒▒
:: Spring Boot :: ${spring-boot.version}
:: Application :: ${application.version}
一旦创建了banner.txt文件,Spring Boot在启动时会自动显示这个横幅。
2、配置
进一步自定义横幅的显示,可以在application.properties或application.yml文件中添加以下配置:
application.properties
spring.banner.location=classpath:custom-banner.txt
spring.banner.image.location=classpath:custom-banner.png
spring.banner.image.width=70
spring.banner.image.height=20
spring.main.banner-mode=console
application.yml
spring:
banner:
location: classpath:custom-banner.txt
image:
location: classpath:custom-banner.png
width: 76
height: 20
main:
banner-mode: console
在这个配置中: spring.banner.location 指定了自定义横幅文件的位置。 spring.banner.image.location 允许你指定一个图片作为横幅。 width 和height 定义了图片横幅的尺寸。 banner-mode 定义了横幅的显示模式,console 表示在控制台显示横幅。不显示任何横幅,可删除banner.txt文件,或者把 banner-mode,可以设置为 off |