In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to customize the Banner of Spring Boot, which is very detailed and has certain reference value. Friends who are interested must finish reading it!
Friends who have used Spring Boot must have seen something like the following in the startup log. For example, when starting Spring Boot, the console will print Spring Boot Logo and version information by default. Is this fixed by Spring Boot or customizable?
. _ _ / / _ _ _ (() _ _ _ |'_ _ _ | |\ / _ _ _ | | | (_ _ | |) )'| _ |. _ _ | _ | | _ | _ | | _\ _ _ | | / = | _ | = | _ _ / = / _ /:: Spring Boot:: (v1.5.7.RELEASE)
The answer is that Spring Boot supports custom Banner, and this article will discuss how to customize Banner content in detail, starting with a look at how Banner came into being.
How did Banner come into being?
The code for the initial Banner is the SpringApplicationBannerPrinter class, and the order in which Spring Boot looks for Banner by default is:
First look for the files banner.gif,banner.jpg and banner.png under Classpath, and use the first to find them
If the above file is not found, continue to search for banner.txt under Classpath.
If none of the above is found, use the default SpringBootBanner, that is, the SpringBoot Logo output above
Generally, the banner.* file is placed in the src/main/resources/ directory.
We can use the attribute banner.location to set Spring Boot to find the above banner.txt file under Classpath. Banner.charset sets the character set of banner.txt, which defaults to UTF-8. The attribute banner.image.location is used to specify the location where the banner. (gif | jpg | png) file is found.
If there are both pictures (such as banner.jpg) and banner.txt, they will be displayed at the same time, with pictures followed by text, but with multiple pictures banner. (gif | jpg | png), only the first picture will be displayed.
For text files, Spring Boot outputs them directly.
For image files (banner.gif, banner.jpg, or banner.png), Spring Boot converts the image to ASCII characters and then outputs.
Variable
Variables can also be used in banner.txt files to set fonts, colors, and version numbers.
The variable describes the version defined in ${application.version} MANIFEST.MF. For example, the version defined in 1. 0 ${application.formatted-version} MANIFEST.MF and add a v prefix. For example: v1.0 ${spring-boot.version} Spring Boot version. For example: 1.5.7.RELEASE$ {spring-boot.formatted-version} Spring Boot version, and add a v prefix. For example: v1.5.7.RELEASE$ {Ansi.NAME} (or ${AnsiColor.NAME}, ${AnsiBackground.NAME}, ${AnsiStyle.NAME}) ANSI color, font ${application.title} application name configuration defined in MANIFEST.MF
Banner-related configurations in application.properties:
# banner mode. There are three modes: console/log/off# console print to console (via System.out) # log-print to log # off-turn off print spring.main.banner-mode = off# banner file encoding spring.banner.charset = UTF-8# banner text file path spring.banner.location = classpath:banner.txt# banner image file path (you can choose png,jpg Gif file) spring.banner.image.location = classpath:banner.gifused). # width of the image banner (number of characters) spring.banner.image.width = 7 height of the image banner (number of characters) spring.banner.image.height = # left boundary of the image banner (number of characters) spring.banner.image.margin = "whether to turn the image to black console theme spring.banner.image.invert = false
Of course, you can also configure it in the YAML file, for example:
Spring: banner: charset: UTF-8 location: classpath:banner.txt example
New Spring Boot project (based on Spring Boot 1.5.7)
Package com.wupx.springboot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class BannerApplication {public static void main (String [] args) {SpringApplication.run (BannerApplication.class, args);}}
Add the banner.txt file to the resources directory in the Spring Boot project as follows:
${AnsiColor.BRIGHT_YELLOW} ${AnsiStyle.BOLD} _\ /\ /\ _\ / /\ / | | _ > > < /\ _ / | _ / _ _ /\ _ | _ _ |\ / ${AnsiColor.CYAN} ${AnsiStyle.BOLD}:: Java :: (v$ {java.version}):: Spring Boot:: (v$ {spring-boot.version}) ${AnsiStyle.NORMAL}
After launching the Spring Boot application, the output Banner of the console is as follows:
Several websites that generate character paintings are recommended. You can put the generated character paintings in this banner.txt file:
Http://www.network-science.de/ascii/
Http://patorjk.com/software/taag
Http://www.degraeve.com/img2txt.php
Summary
The default SpringBoot registers a singleton Bean of SpringBootBanner, which is used to print the Banner.
If you want to fully customize the Banner, you can first implement the org.springframework.boot.Banner#printBanner interface to customize the Banner. After injecting this Banner into Spring Boot through the SpringApplication.setBanner () method.
A general custom Spring Boot Banner is the Slogan of an enterprise / team / project.
The above is all the contents of the article "how to customize Spring Boot's Banner". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.