博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring-Boot Banner
阅读量:4949 次
发布时间:2019-06-11

本文共 8262 字,大约阅读时间需要 27 分钟。

下载Spring-Boot源码,目录结构spring-boot-2.1.0.M2\spring-boot-2.1.0.M2\spring-boot-project\spring-boot\src\main\java\org\springframework\boot

Banner为接口具体实现类二个,https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/api/ 

一个存放图片资源,一个存放资源。

package com.jachs.jurisdiction.Jurisdiction;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import org.springframework.boot.ImageBanner;import org.springframework.boot.ResourceBanner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;import org.springframework.core.io.InputStreamResource;@SpringBootApplicationpublic class JurisdictionApplication{    /*    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        System.out.println("in");        try {            builder.banner(new ImageBanner(new InputStreamResource(new FileInputStream("C:\\Users\\Jachs\\Desktop\\a.png"))));        } catch (FileNotFoundException e) {            e.printStackTrace();        }        return builder.sources(JurisdictionApplication.class);    }    */    public static void main(String[] args) throws FileNotFoundException {        // SpringApplication.run(LoginAction.class, args);//        SpringApplication.run(JurisdictionApplication.class, args);        SpringApplication application = new SpringApplication(JurisdictionApplication.class);        application.setBanner(new ImageBanner(new InputStreamResource(new FileInputStream("C:\\Users\\Jachs\\Desktop\\a.png"))));//        application.setBanner(new ResourceBanner(new InputStreamResource(new FileInputStream("C:\\Users\\Jachs\\Desktop\\s.txt"))));        application.run(args);    }}

实现ImageBanner是打印的为图片二进制,为实现自己独特的打印采用ResourceBanner指定一个文本写入类容初始化时打印。

*******************************************************HellWord*********************************************************2018-09-14 16:25:21.462  INFO 5940 --- [           main] c.j.j.J.JurisdictionApplication          : Starting JurisdictionApplication on ZhanChaoHan with PID 5940 (C:\Users\Jachs\Downloads\Jurisdiction\target\classes started by zhanchaohan in C:\Users\Jachs\Downloads\Jurisdiction)2018-09-14 16:25:21.467  INFO 5940 --- [           main] c.j.j.J.JurisdictionApplication          : No active profile set, falling back to default profiles: default2018-09-14 16:25:23.480  INFO 5940 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)2018-09-14 16:25:23.517  INFO 5940 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2018-09-14 16:25:23.517  INFO 5940 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.122018-09-14 16:25:23.531  INFO 5940 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\jdk-8u5-windows-x64\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/jdk-8u5-windows-x64/bin/../jre/bin/server;D:/jdk-8u5-windows-x64/bin/../jre/bin;D:/jdk-8u5-windows-x64/bin/../jre/lib/amd64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;F:\MySql\bin;D:\php-7.0.10\php-7.0.10;D:\php-7.0.10\php-7.0.10\ext;F:\TortoiseSVN\bin;F:\VisualSVN-Server-3.5.6-x64.msi\VisualSVN Serve\bin;E:\BaiDu\C#\运行Java\ikvm-7.2.4630.5\bin;D:\aspectj1.8\bin;D:\cygwin\bin;F:\Git\cmd;E:\BaiDu\JAVA\java\Apache\Maven\gradle-4.6-bin\gradle-4.6\bin;D:\jdk-8u5-windows-x64\bin;E:\BaiDu\JAVA\java\Apache\Maven\apache-maven-3.5.3-bin\apache-maven-3.5.3\bin;F:\es\zookeeper\bin;F:\es\kafka-eagle-bin-1.2.3\kafka-eagle-bin-1.2.3\kafka-eagle-web-1.2.3-bin\bin;E:\sts-bundle\sts-3.8.4.RELEASE;;.]2018-09-14 16:25:23.720  INFO 5940 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2018-09-14 16:25:23.720  INFO 5940 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2187 ms2018-09-14 16:25:23.766  INFO 5940 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]2018-09-14 16:25:23.772  INFO 5940 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]2018-09-14 16:25:23.773  INFO 5940 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]2018-09-14 16:25:23.773  INFO 5940 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]2018-09-14 16:25:23.774  INFO 5940 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]2018-09-14 16:25:23.859  INFO 5940 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService  'applicationTaskExecutor'2018-09-14 16:25:24.699  INFO 5940 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''2018-09-14 16:25:24.706  INFO 5940 --- [           main] c.j.j.J.JurisdictionApplication          : Started JurisdictionApplication in 4.06 seconds (JVM running for 4.971)2018-09-14 16:25:25.447  INFO 5940 --- [on(2)-127.0.0.1] inMXBeanRegistrar$SpringApplicationAdmin : Application shutdown requested.2018-09-14 16:25:25.452  INFO 5940 --- [on(2)-127.0.0.1] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

默认打印采用的是SpringBootBanner代码如下,可以自己改造

/* * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.springframework.boot;import java.io.PrintStream;import org.springframework.boot.ansi.AnsiColor;import org.springframework.boot.ansi.AnsiOutput;import org.springframework.boot.ansi.AnsiStyle;import org.springframework.core.env.Environment;/** * Default Banner implementation which writes the 'Spring' banner. * * @author Phillip Webb */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(); }}

不想显示初始化Banner时。

application.setBannerMode(Mode.OFF);
Mode说明

该枚举三个CONSOLE打印到控制台,LOG打印到log日志,OFF不打印。

 

转载于:https://www.cnblogs.com/zhanchaohan/p/9647458.html

你可能感兴趣的文章
SQL Server: Enable xp_cmdshell using sp_configure
查看>>
LOJ #2116 Luogu P3241「HNOI2015」开店
查看>>
接口测试工具postman
查看>>
jQuery取得select选择的文本与值
查看>>
UIPageControl自定义点的颜色
查看>>
逻辑卷管理
查看>>
驱动绕过360的KiFastCallEntry钩子
查看>>
树是一种特殊的图
查看>>
Regex Golf练习笔记(1)
查看>>
LeetCode-Swap Nodes in Pairs
查看>>
windows下安装ffmpeg(php视频处理扩展)
查看>>
CDOJ 1259 昊昊爱运动 II bitset+线段树
查看>>
SpringBoot自定义注解、AOP打印日志
查看>>
python_15_os
查看>>
Common工具类的验证码类的使用(未实现验证)
查看>>
使用Jsoup获取网页内容超时设置
查看>>
img 的 3px
查看>>
Codeforces Round #384 (Div. 2) D. Chloe and pleasant prizes(树形DP)
查看>>
flex布局中flex-basis的理解
查看>>
93. Restore IP Addresses
查看>>