睁眼写BUG,闭眼改BUG。

Spring Boot (1) 配置

2019.06.23

回顾spring boot, 开发属于自己的博客(空间)准备.

Spring Boot 基础配置

详细参考旧址

@SpringBootApplication

@SpringBootAplication 注解是加在启动类上的. 是一个组合注解, 相当于:

@SpringBootConfiguration // spring boot 配置
@EnableAutoConfiguration // 开启自动配置
@ComponentScan(excludeFilters = { 
     @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
      @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) }) // 包扫描
public @interface SpringBootApplication {
	// ...
}

小提示:
@ComponentScan 注解, 会扫描 @Service @Repository @Component @Controller @RestController @Configuration

@SpringBootConfiguration

相当于:

@Configuration
public @interface SpringBootConfiguration {
	// ...
}

配置Bean

@Configuration
public class MyConfig {
	// ...
}

定制 banner

在 resources 下创建一个 banner.txt 文件, 在文件中写入的文本将在项目启动时打印. 替换掉原本Spring Boot 标志.

艺术字生成:

关闭 banner

public static void main(String[] args) {
	SpringApplicationBuilder builder = new SpringApplicationBuilder(xxx.class);
	builder.bannerMode(Banner.Mode.OFF).run(args);
}

properties 配置

参考文档

建议 yml 配置

application.properties 加载优先级

    1. 项目目录下config下
    1. src下
    1. resources下config下
    1. resources下

yml 同理