1. Banner introduction
Spring Boot Banner is a feature for displaying custom ASCII art and information at application startup. This ASCII art usually includes the project name, version number, author information, etc. The main role of a banner is to enhance the app’s brand identity while providing a friendly welcome that makes the user or developer feel happy when launching the app. Generating custom banners can bring the following benefits and benefits to your project:
- Brand identity: By displaying custom ASCII art and information at launch, you can add a unique identity to your project and improve the user experience.
- Welcome message: Banners can contain a welcome message that communicates information about the app to users or team members.
- Version number and author information: You can include the version number and author information of your application in your banner to make it easier to identify the version and owner of your application.
Banner usage scenarios
Generating custom Spring Boot Banners is suitable for the following scenarios:
- Project branding: You can use custom banners when you want to add a unique logo to your project and provide a friendly welcome message.
- Version management: When deploying an application in multiple environments, you can easily distinguish between different versions by including the version number in the banner.
- Project team: If you want to display the project’s author information or development team information in a banner, you can use a custom banner.
Banner configuration
To configure and enable custom banners in your Spring Boot project, you can follow these steps: 1. Create a text file and name it banner.txt
and place it in the project src/main/resources
directory.
2. Code engineering
Objective: Customize the banner
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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
Generate your own project’s banner at this URL and paste the generated content into /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
############################################################################################################
You can use variables to read the contents of a configuration file
Startup class
package com.et.banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
application.yaml
server:
port: 8088
application:
title: banner-test
version: V2.2.5
The above are just some of the key codes, all of which can be found in the repositories below
Code repositories
3. Testing
Start the Spring Boot application and view the output information in the console
############################################################################################################
,---. ,--. ,-----. ,--. ,------.
' .-' ,---. ,--.--.`--',--,--, ,---. | |) /_ ,---. ,---. ,-' '-. | .-. \ ,---. ,--,--,--. ,---.
`. `-.| .-. || .--',--.| \| .-. | | .-. \| .-. | .-. |'-. .-' | | \ :| .-. :| || .-. |
.-' | '-' '| | | || || |' '-' ' | '--' /' '-' ' '-' ' | | | '--' /\ --.| | | |' '-' '
`-----'| |-' `--' `--'`--''--'.`- / `------' `---' `---' `--' `-------' `----'`--`--`--' `---'
`--' `---'
banner-test V2.2.5
Powered by Spring Boot 2.2.5.RELEASE
generate by https://devops.datenkollektiv.de/banner.txt/index.html
############################################################################################################