SpringBoot官网文档:2.1.5
原文地址:
官网文档
中文文档翻译
笔记:
1、可以使用 @ComponentScan 自动扫描所有 Spring 组件,包括 @Configuration 类。
2、所有应用组件(@Component、@Service、@Repository、@Controller 等)将自动注册为 Spring Bean。
3、在主启动类加载完成后执行:implements ApplicationRunner/CommandLineRunner
4、SpringApplication 从以下位置的 application.properties 文件中加载属性(properties),并将它们添加到 Spring Environment 中:
- 1.当前目录的 /config 子目录
- 2.当前目录
- 3.classpath 上的 /config 包
- 4.classpath 根路径
列表按序号优先级排序,序号越小,优先级越高。
5、属性配置文件:
- 1.导入配置文件
@PropertySource("classpath:application-user.properties")
- 2.给属性赋值
@Component
@ConfigurationProperties(prefix="user")
6、日志:
开启debug:debug=true
日志输出位置:logging.file.name=my.log