Java --- springboot3自定义banner与SpringApplication

本文介绍了如何自定义SpringBoot的启动banner,包括使用在线工具生成并替换banner.txt,以及修改配置文件来设置显示。同时,文章讲解了两种自定义SpringApplication的方法,一种是直接设置Banner模式,另一种是通过FluentBuilderAPI构建和运行应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、自定义banner

二、 自定义SpringApplication


一、自定义banner

生成banner网站:Spring Boot banner在线生成工具,制作下载英文banner.txt,修改替换banner.txt文字实现自定义,个性化启动banner-bootschool.net

修改springboot的配置文件

#修改为自己定义的banner
spring.banner.location=classpath:banner.txt
#banner的模式
spring.main.banner-mode=off

 测试结果:

 

二、 自定义SpringApplication

方式一:

@SpringBootApplication
public class Boot3FeaturesApplication {

    public static void main(String[] args) {
        //SpringApplication:springboot应用的核心API入口
        //SpringApplication.run(Boot3FeaturesApplication.class, args);
        //自定义SpringApplication的底层设置
        SpringApplication application = new SpringApplication(Boot3FeaturesApplication.class);
        //设置banner,如果配置文件配置了以配置文件优先
        application.setBannerMode(Banner.Mode.CONSOLE);
        //运行程序
        application.run(args);
    }

}

方式二:FluentBuilder API

public static void main(String[] args) {
        //通过Builder方式构建
         new SpringApplicationBuilder()
                 .main(Boot3FeaturesApplication.class)
                 .sources(Boot3FeaturesApplication.class)
                 .bannerMode(Banner.Mode.CONSOLE)
                 .run(args);
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鸭鸭老板

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值