欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

springboot之banner

程序员文章站 2022-06-22 11:53:14
springboot在正常启动的时候默认打印的如下: 源码如下: class SpringBootBanner implements Banner { private static final String[] BANNER = { "", " . ____ _ __ _ _", " /\\\\ / ......

springboot在正常启动的时候默认打印的如下:

springboot之banner

源码如下:

springboot之banner
class springbootbanner implements banner {

    private static final string[] banner = { "",
            "  .   ____          _            __ _ _",
            " /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\",
            "( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\",
            " \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )",
            "  '  |____| .__|_| |_|_| |_\\__, | / / / /",
            " =========|_|==============|___/=/_/_/_/" };

    private static final string spring_boot = " :: spring boot :: ";

    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();
    }

}
view code

对于banner的输出可以做如下修改,代码如下:

banner.txt

                   _ooooo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  o\  =  /o
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无bug

application.yml

spring:
  banner:
    charset: utf-8
    location: banner.txt

application

@springbootapplication
public class application {
    public static void main(string[] args) {
//        springapplication application = new springapplication();
//        application.setbannermode(banner.mode.off);
//        application.run(application.class, args);
        springapplication.run(application.class, args);

    }
}

程序启动后如下:

springboot之banner

更高级的操作,后续再进行研究