Springboot自定义banner启动动画
在Spring Boot中,可以通过实现Banner
接口来自定义启动banner。如果想要完全关闭banner,可以设置spring.main.banner-mode
属性为off
。
以下是一个简单的自定义banner的示例代码:
import org.springframework.boot.Banner;
import org.springframework.core.env.Environment;
import java.io.PrintStream;
public class CustomBanner implements Banner {
private static final String BANNER =
" _ _ ____ _ \n" +
" | | ___ ___ ___ | | ___ / ___|| | ___ _ __ \n" +
" | | / _ \\ / __| / __| | | / _ \\ \\___ \\| | / _ \\ | '__| \n" +
" | |__| (_) | (__ \\__ \\ | | | (_) | ___) | | | __/ | | \n" +
" |____\\___/ \\___| |___/ |_| \\___/ |____/ |_| \\___| |_| \n" +
" ";
@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
out.println(BANNER);
}
}
然后在Spring Boot应用的main
方法中使用这个自定义banner:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(MyApplication.class);
app.setBanner(new CustomBanner());
app.run(args);
}
}
如果你想关闭banner,可以在application.properties
或application.yml
文件中添加以下配置:
spring.main.banner-mode=off
或者在application.yml
中:
spring:
main:
banner-mode: off
评论已关闭