首先我们来简单看看spring boot启动是如何打印banner的源码:
入口:在SpringApplication.run方法中会调用printBanner打印
这里判断是往控制台还是日志中打印
继续下潜,有个getBanner,这个就是自定义Banner的关键了:
获取自定义的图标banner和文字banner,如果没有自定义则使用spring boot 默认的banner
图标banner是通过配置“spring.banner.image.location”自定义的,文字则和配置spring.banner.location有关
那么自定义配置的逻辑就很简单了,做个简单的示例:
我们在resource下放一张hello.jpg和banner.txt
然后在配置文件yml中定义“spring.banner.image.location”和"spring.banner.location"配置
这样启动就可以了,我们来看看效果: