SpringBoot启动图标修改

Springboot自定义启动图标:

一、demo:


                                                  88
                                                  ""

8b      db      d8 8b,     ,d8 88,dPYba,,adPYba,  88 8b,dPPYba,   ,adPPYb,d8
`8b    d88b    d8'  `Y8, ,8P'  88P'   "88"    "8a 88 88P'   `"8a a8"    `Y88
 `8b  d8'`8b  d8'     )888(    88      88      88 88 88       88 8b       88
  `8bd8'  `8bd8'    ,d8" "8b,  88      88      88 88 88       88 "8a,   ,d88
    YP      YP     8P'     `Y8 88      88      88 88 88       88  `"YbbdP"Y8
                                                                  aa,    ,88
                                                                   "Y8bbdP"

${AnsiColor.BRIGHT_BLUE}:: Running Spring Boot ${spring-boot.version} ::

二、效果:

三、理论讲解:

自定义banner只需要在resource下新建一个banner.txt文件,将我们需要的banner字样放进去,启动的时候就会去读取使用这个文本文件中的banner。

控制banner样式

Spring提供了三个枚举类来设定字符的颜色,分别是:

AnsiColor: 用来设定字符的前景色

AnsiBackground: 用来设定字符的背景色

AnsiStyle: 用来控制加粗、斜体、下划线等等。

使用${AnsiFoo.Bar}来指定样式,当指定样式的时候会有提示的。

 

且可以给每部分写具体的样式:指定了颜色之后直到下次指定之前的字符都是FooColor颜色的。

demo:


                                                  ${AnsiColor.RED}88${AnsiColor.BLUE}
                                                  ""

8b      db      d8 8b,     ,d8 88,dPYba,,adPYba,  88 8b,dPPYba,   ,adPPYb,d8${AnsiColor.BRIGHT_YELLOW}
`8b    d88b    d8'  `Y8, ,8P'  88P'   "88"    "8a 88 88P'   `"8a a8"    `Y88
 `8b  d8'`8b  d8'     )888(    88      88      88 88 88       88 8b       88
  `8bd8'  `8bd8'    ,d8" "8b,  88      88      88 88 88       88 "8a,   ,d88
    YP      YP     8P'     `Y8 88      88      88 88 88       88  `"YbbdP"Y8
                                                                  aa,    ,88
                                                                   "Y8bbdP"

${AnsiColor.BRIGHT_BLUE}:: Running Spring Boot ${spring-boot.version} ::

效果:

显示应用信息

除了上面的指定样式之外,还可以显示一些与应用相关的版本信息:

${application.version}   与MANIFEST.MF文件中相同的版本号,比如1.5.4.RELEASE

${application.formatted-version}   格式化过的版本号就是加个v然后用括号包起来,比如(v1.5.4.RELEASE)

${application.title} 

${spring-boot.version} Spring Boot的版本

${spring-boot.formatted-version} 格式化过的版本

控制banner是否开启,输出位置

设置banner mode为OFF关闭banner:

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootStudy002Application {

	public static void main(String[] args) {
		SpringApplication springApplication = new SpringApplication(SpringBootStudy002Application.class);
		springApplication.setBannerMode(Banner.Mode.OFF);
		springApplication.run(args);
	}
}

几个常用的字符画生成网站

===================================================

下面介绍如何自定义为gif动图:

打开网址:https://giphy.com/     搜索 ascii

点击任意gif进行下载

然后将下载下来的 .gif文件复制到resources/目录下改名名为banner.gif即可

注意,如此操作在ide中无法实现动图动态展示,我们需要在命令行中启动项目,两种方式都可以:

1.切换到项目目录中  mvn springboot:run

2.切换到项目目录中 mvn install

                 切换到 target目录 java -jar 打包好的项目

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值