Spring Boot Banner 是一个用于在应用程序启动时显示自定义 ASCII 艺术和信息的功能。这个 ASCII 艺术通常包括项目名称、版本号、作者信息等。Banner 的主要作用是增强应用程序的品牌标识,同时提供一种友好的欢迎方式,让用户或开发人员在启动应用程序时感到愉快。 生成自定义 Banner 可以为项目带来以下优势和便利:
品牌标识:通过在启动时显示自定义 ASCII 艺术和信息,你可以为你的项目增加独特的标识,提高用户体验。
欢迎信息:Banner 可以包含欢迎信息,用于向用户或团队成员传达有关应用程序的信息。
版本号和作者信息:你可以在 Banner 中包含应用程序的版本号和作者信息,以便更容易地识别应用程序的版本和负责人。
生成自定义 Spring Boot Banner 适用于以下场景:
项目品牌标识:当你希望为项目增加独特的标识并提供友好的欢迎信息时,可以使用自定义 Banner。
版本管理:在多个环境中部署应用程序时,通过在 Banner 中包含版本号,可以轻松区分不同的版本。
项目团队:如果你想在 Banner 中显示项目的作者信息或开发团队信息,可以使用自定义 Banner。
要在 Spring Boot 项目中配置和启用自定义 Banner,可以按照以下步骤进行操作: 1、创建一个文本文件,命名为 banner.txt,并将其放置在项目的 src/main/resources 目录下。
实验目标:自定义banner
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-demo</artifactId><groupId>com.et</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>banner</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies></project>
在这个网址生成自己项目的banner,生成内容粘贴到/resources/banner.txt里面 https://devops.datenkollektiv.de/banner.txt/index.html
############################################################################################################,---. ,--. ,-----. ,--. ,------.' .-' ,---. ,--.--.`--',--,--, ,---. | |) /_ ,---. ,---. ,-' '-. | .-. \ ,---. ,--,--,--. ,---.`. `-.| .-. || .--',--.| \| .-. | | .-. \| .-. | .-. |'-. .-' | | \ :| .-. :| || .-. |.-' | '-' '| | | || || |' '-' ' | '--' /' '-' ' '-' ' | | | '--' /\ --.| | | |' '-' '`-----'| |-' `--' `--'`--''--'.`- / `------' `---' `---' `--' `-------' `----'`--`--`--' `---'`--' `---'${application.title} ${application.version}Powered by Spring Boot ${spring-boot.version}generate by https://devops.datenkollektiv.de/banner.txt/index.html############################################################################################################
可以使用变量读取配置文件里面的内容
package com.et.banner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}
server:port: 8088application:title: banner-testversion: V2.2.5
以上只是一些关键代码,所有代码请参见下面代码仓库
https://github.com/Harries/springboot-demo
启动Spring Boot应用,查看控制台输出信息
############################################################################################################,---. ,--. ,-----. ,--. ,------.' .-' ,---. ,--.--.`--',--,--, ,---. | |) /_ ,---. ,---. ,-' '-. | .-. \ ,---. ,--,--,--. ,---.`. `-.| .-. || .--',--.| \| .-. | | .-. \| .-. | .-. |'-. .-' | | \ :| .-. :| || .-. |.-' | '-' '| | | || || |' '-' ' | '--' /' '-' ' '-' ' | | | '--' /\ --.| | | |' '-' '`-----'| |-' `--' `--'`--''--'.`- / `------' `---' `---' `--' `-------' `----'`--`--`--' `---'`--' `---'banner-test V2.2.5Powered by Spring Boot 2.2.5.RELEASEgenerate by https://devops.datenkollektiv.de/banner.txt/index.html############################################################################################################
https://devops.datenkollektiv.de/banner.txt/index.html
http://www.liuhaihua.cn/archives/710608.html
原文作者:HBLOG;如有侵权,请联系管理员删除。