Spring Boot扩展启动行为-改变启动Banner

跟杨春娟学SpringBoot笔记:Spring Boot扩展启动行为-改变启动Banner

完成:第一遍

1.如何改变启动Banner?

可以使用文件的方式来设置Banner
可以从网站拷贝以ASCII码来展示Banner

可以转换ASCII码Banner的网址

第一种方式:在SpringBootDemoProjectApplication 通过setBanner()来设置Banner
src/main/resources下有个banner.txt

package com.springboot.demo.SpringBootDemoProject;

import org.springframework.boot.Banner.Mode;
import org.springframework.boot.ResourceBanner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;

import com.springboot.demo.SpringBootDemoProject.configuration.AWSConfigBean;
import com.springboot.demo.SpringBootDemoProject.configuration.RandomConfigBean;

@SpringBootApplication
@PropertySource("classpath:config.properties")
@EnableConfigurationProperties({AWSConfigBean.class, RandomConfigBean.class})
public class SpringBootDemoProjectApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringBootDemoProjectApplication.class, args);	
		//SpringApplication springApplication = new SpringApplication(SpringBootDemoProjectApplication.class);
		
		//关闭启动Banner
		//springApplication.setBannerMode(Mode.OFF);
		
		//设置启动banner
		/*
		 * springApplication.setBanner(new ResourceBanner(new
		 * ClassPathResource("banner.txt")));
		 * springApplication.setBannerMode(Mode.CONSOLE);
		 * 
		 * springApplication.run(args);
		 */
	}

}

第二种方式:在ApplicationContext.properties中
设置Banner

spring.banner.charset=UTF-8
spring.banner.location=classpath:banner.txt
spring.banner.image.location=classpath:banner.jpg
spring.banner.image.width=76
spring.banner.image.invert=false

关闭Banner

spring.main.banner-mode=OFF
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页