-
SpringBoot的配置文件支持properties和yml格式,甚至还支持json。
更推荐使用yml文件格式:
-
yml文件,换行和缩进帮助管理配置文件所在位置
-
yml文件,相比properties更轻量
yml文件的劣势:
-
严格遵循换行和缩进
-
在填写value时,一定要在":"号后面加上空格
-
-
多环境配置
a. 创建多个环境的配置文件,文件命名为application-环境名.yml
b. 在application.yml中加入下面的配置:
spring:
profiles:
active: dev
- 引入外部配置文件信息
a.按照原来方式引入
@Value("${test}")
private String test;
b.如果配置项比较多时,可以采用新创建配置类的方式实现
@ConfigurationProperties(prefix = "aliyun")
@Component
@Data
public class AliyunProperties{
private String xxx;
private String yyy;
}
yml文件配置:
aliyun:
xxx: xxxx
yyy: yyyy
- 热部署
a. 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
b. 设置项目编译可以自动build,pycharm的设置路径:Setting->build->compile, 勾选build automatically选项
c. 修改项目内容后,只需要,点击pycharm最上面的Build选项->build,即可完成项目的部署