write first
When we start the Spring Boot project, the following will be printed on the console (logo and version information):
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.6)
复制代码
hands-on replacement
Generate Banner
You can generate the ASCII art word you want for your project through the following link
Generate banner characters as follows
To My Love!
-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-
__ __ __ __
.*. /~ .~\ /~ ~\ /~ .~\ /~ ~\
*** ' `\/' * ' `\/' *
V ( .*)( . *)
/\|/\ \ Ming . *./ \ Yue . *./
| `\ . . .*/' `\ . . .*/' .*.
| `\ * .*. */' _ _ `\ * .*. */' ***
`\ * */' ( `\/'*) `\ * */' V
`\/' \ */' `\/' /\|/\
`\/' |
--+++==##<<{{******** Ming Yue ********}}>>##==++--
复制代码
Replace Banner
Create a
banner.txt
file . For example:banner
replace
Start the project again and print the banner characters as above. At this point, we found that some version information of the corresponding Spring Boot is missing. If you still want it, you can add it.
Append Spring Boot version information, etc.
- ${spring-boot.version}: Spring Boot version number;
- ${spring-boot.formatted-version}: The formatted version number of Spring Boot.
- ${application.version}: the version number in the MANIFEST.MF file;
- ${application.formatted-version}: version number information in the formatted MANIFEST.MF file;
Append the variables defined
application.properties
in
app.author=Strive
复制代码
The final file is as follows, start the project again to view and print
To My Love!
-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-
__ __ __ __
.*. /~ .~\ /~ ~\ /~ .~\ /~ ~\
*** ' `\/' * ' `\/' *
V ( .*)( . *)
/\|/\ \ Ming . *./ \ Yue . *./
| `\ . . .*/' `\ . . .*/' .*.
| `\ * .*. */' _ _ `\ * .*. */' ***
`\ * */' ( `\/'*) `\ * */' V
`\/' \ */' `\/' /\|/\
`\/' |
--+++==##<<{{******** Ming Yue ********}}>>##==++--
:: Spring Boot :: (${spring-boot.version})
--by ${app.author}
复制代码
It prints as follows:
To My Love!
-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-
__ __ __ __
.*. /~ .~\ /~ ~\ /~ .~\ /~ ~\
*** ' `\/' * ' `\/' *
V ( .*)( . *)
/\|/\ \ Ming . *./ \ Yue . *./
| `\ . . .*/' `\ . . .*/' .*.
| `\ * .*. */' _ _ `\ * .*. */' ***
`\ * */' ( `\/'*) `\ * */' V
`\/' \ */' `\/' /\|/\
`\/' |
--+++==##<<{{******** Ming Yue ********}}>>##==++--
:: Spring Boot :: (2.6.6)
--by Strive
复制代码
Implementation principle
Banner
The interface specifically implements this operation. To customize the printing banner, just customize a class to implement this interface and override theprintBanner
method to print. When the Springboot project starts, our implementation class object is created and theprintBanner
method .
package org.springframework.boot;
import java.io.PrintStream;
import org.springframework.core.env.Environment;
@FunctionalInterface
public interface Banner {
void printBanner(Environment environment, Class<?> sourceClass, PrintStream out);
public static enum Mode {
OFF, // 关闭 banner 打印
CONSOLE, // 打印 banner 到 控制台
LOG; // 打印 banner 到日志文件
private Mode() {
}
}
}
复制代码
printBanner
There are three implementations by default:
- ImageBanner: Load and print image banner;
- ResourceBanner: Load and print character banner;
- SpringBootBanner: By default, the SpringBootBanner implementation class is used to print the banner;