自定义 spring boot 启动图案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37960603/article/details/84454616

首先去这个网站 传送门,输入想要的图案,选择自己喜欢的字体,会得到对于的图案,copy 图案。
如下图:
在这里插入图片描述
图案如下:

   _  __      _    __     __ U _____ u _   _
  |"|/ /  U  /"\  u\ \   /"/u\| ___"|/| \ |"|
  | ' /    \/ _ \/  \ \ / //  |  _|" <|  \| |>
U/| . \\u  / ___ \  /\ V /_,-.| |___ U| |\  |u
  |_|\_\  /_/   \_\U  \_/-(_/ |_____| |_| \_|
,-,>> \\,-.\\    >>  //       <<   >> ||   \\,-.
 \.)   (_/(__)  (__)(__)     (__) (__)(_")  (_/

在 spring boot 项目下的 resources 包下创建 banner.txt 并且粘贴 copy 的图案。
如下图:
在这里插入图片描述

启动 spring boot 项目,可以看到图案效果。
如下图:
在这里插入图片描述

但是没有颜色,效果还是不太好。
spring boot 提供了一个枚举类 AnsiColor ,这个类可以控制 banner.txt 中的字符颜色,而且使用也非常简单。
AnsiColor.java 源码:

/*
 * Copyright 2012-2017 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.ansi;

/**
 * {@link AnsiElement Ansi} colors.
 *
 * @author Phillip Webb
 * @author Geoffrey Chandler
 * @since 1.3.0
 */
public enum AnsiColor implements AnsiElement {

	DEFAULT("39"),

	BLACK("30"),

	RED("31"),

	GREEN("32"),

	YELLOW("33"),

	BLUE("34"),

	MAGENTA("35"),

	CYAN("36"),

	WHITE("37"),

	BRIGHT_BLACK("90"),

	BRIGHT_RED("91"),

	BRIGHT_GREEN("92"),

	BRIGHT_YELLOW("93"),

	BRIGHT_BLUE("94"),

	BRIGHT_MAGENTA("95"),

	BRIGHT_CYAN("96"),

	BRIGHT_WHITE("97");

	private final String code;

	AnsiColor(String code) {
		this.code = code;
	}

	@Override
	public String toString() {
		return this.code;
	}

}

简单使用如下:

${AnsiColor.CYAN}
   _  __      _    __     __ U _____ u _   _
  |"|/ /  U  /"\  u\ \   /"/u\| ___"|/| \ |"|
  | ' /    \/ _ \/  \ \ / //  |  _|" <|  \| |>
U/| . \\u  / ___ \  /\ V /_,-.| |___ U| |\  |u
  |_|\_\  /_/   \_\U  \_/-(_/ |_____| |_| \_|
,-,>> \\,-.\\    >>  //       <<   >> ||   \\,-.
 \.)   (_/(__)  (__)(__)     (__) (__)(_")  (_/
${AnsiColor.BRIGHT_RED}
  Project (version): Spring-Boot ${spring-boot.version}

效果如下图:
在这里插入图片描述

这样就可以根据自己喜欢的颜色搭配来自定义图案了。

猜你喜欢

转载自blog.csdn.net/qq_37960603/article/details/84454616