In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use banner in SpringBoot". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use banner in SpringBoot" can help you solve the problem.
Make your own banner
Step 1: create a banner.txt under src/main/resources.
Step 2: visit the website http://patorjk.com/software/taag and enter the word you want to make at the site "Type Something" (such as Hello World), which will generate the corresponding characters. You can also adjust the style of characters through other parameters.
Copy the generated characters, paste them into banner.txt, and start the program again to print out the specified banner.
My favorite banner is the following graphics:
${AnsiColor.BRIGHT_YELLOW} / _ ooOoo_ / o8888888o / 88 ". "88 / (| ^ _ ^ |) / O\ = / O / _ / `- -'\ _ /.'\\ | | / /. /\\ | / _ |-- |-/ | |\ / | | / |\ _ |'\-- /'| | /\. -\ _ _ `-` _ / -. / _ _ .'/ -. . _ /. "'
< `.___\__/___.' >"". / | |: `-\`.; `\ _ /`; .` /-`: | | /\\` -. \ _\ / _ /.-`/ =` -. _ `-. _ / _. -` _. -'= / `=-='/ ^ ^ / Buddha blesses never to go down. BUG /
In the new version of SpringBoot, banner printing in the form of pictures of gif, jpg and png is supported. Of course, the picture will not be printed directly on the console, but will be parsed into assii encoding and then printed.
For gif motion pictures, each picture of the motion picture will be printed out. If the motion picture is larger, the printing time will be longer. You can give it a try, but it is not recommended to use gif.
In banner.txt, you can also make some settings, such as ${AnsiColor.BRIGHT_YELLOW} in the figure above.
AnsiColor.BRIGHT_RED: sets the color of the output in the console
Application.version: used to get the version number in the MANIFEST.MF file
Application.formatted-version: formatted application.version version information
The version number of spring-boot.version:Spring Boot
Spring-boot.formatted-version: formatted spring-boot.version version information
Banner interface
Where are the default graphics stored when no banner.txt or banner pictures are specified? Let's take a look at the Banner interface.
@ FunctionalInterfacepublic interface Banner {/ / print banner void printBanner (Environment environment, Class sourceClass, PrintStream out); enum Mode {/ / close OFF, / / console CONSOLE, / / log file LOG}}
A method for printing banner and an enumeration class are provided in the banner interface. The enumeration class has three values: OFF, CONSOLE, and LOG, which are used to control the printing of banner, corresponding to: turning off printing, console printing, and log printing.
The implementation of banner interface mainly includes ResourceBanner, ImageBanner, SpringBootBanner and other inner classes. The graphics seen above are printed from SpringBootBanner. Look at the source code:
Class SpringBootBanner implements Banner {private static final String [] BANNER = {",". _ _ _ ", / / _ _ _ (_) _ _ _ (_)," (()\ _ _ _ |'_ | |'_\ / _ _ `|\\ " "\\ / _) | | _) | | | (_ | |)", "'| _ |. _ _ | _ | | _ | | _\ _, /", "," = | _ | = | _ _ / = / _ / "} Private static final String SPRING_BOOT = ":: SpringBoot::"; private static final int STRAP_LINE_SIZE = 42; @ Override public void printBanner (Environment environment, Class sourceClass, PrintStream printStream) {for (String line: BANNER) {printStream.println (line);} String version = SpringBootVersion.getVersion (); version = (version! = null)? " (v "+ version +"): "; StringBuilder padding = new StringBuilder (); while (padding.length () < STRAP_LINE_SIZE-(version.length () + SPRING_BOOT.length () {padding.append (");} printStream.println (AnsiOutput.toString (AnsiColor.GREEN, SPRING_BOOT, AnsiColor.DEFAULT, padding.toString (), AnsiStyle.FAINT, version)); printStream.println ();}}
In the implementation of the printBanner method, the default Banner string array is printed first, and then the SPRING_BOOT and version information are spliced and printed.
Parameter setting of Banner
The parameters of banner can be set in two forms, one is in the form of code, the other is in the form of configuration files.
In the form of code, the first step is to modify the default main method, manually create the SpringApplication object, and then set the appropriate parameters. Sample code:
Public static void main (String [] args) {SpringApplication app = new SpringApplication (SpringbootBannerApplication.class); app.setBannerMode (Banner.Mode.CONSOLE); Banner banner = new ImageBanner (new ClassPathResource ("banner1.png")); app.setBanner (banner); app.run (args);}
Through the configuration file setting is relatively simple, directly in the application.properties configuration, springboot has helped us prefabricate the corresponding parameters.
Spring.banner.location=classpath:banner1.pngspring.banner.image.margin=2spring.banner.image.height=76spring.banner.charset=UTF-8spring.banner.image.invert=falsespring.banner.image.location=banner1.pngspring.main.banner-mode=consolespring.main.show-banner=true
Among them, spring.main.show-banner controls whether to print banner, which is not recommended in the new version. You can use spring.main.banner-mode instead and set its value to OFF to turn off the printing of banner.
The introduction of text banner is specified through spring.banner.location, and the path of image-related banner needs to be specified through spring.banner.image.location, otherwise garbled will occur.
If you do not want to display the banner, you can turn off printing of the banner in the code through the setBannerMode (Banner.Mode.OFF) method or by configuring the spring.main.banner-mode=off parameter. It has been shown in the above example.
This is the end of the introduction to "how to use banner in SpringBoot". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.