学习视频链接:小狂神Springboot
官方给的执行优先级
在真实工作中,我们会有很多配置文件,比如test,dev,等等,
格式:application-{什么类型的配置}.yml/properties
使用的:spring.profiles.active
主文件
#Springboot多环境配置,可以选择激活那个配置文件
spring.profiles.active=dev
可以有多个配置文件,从主文件选择使用什么开发环境
application-dev.properties 开发项目环境:
server.port=8081
application-test.properties 测试开发环境
server.port=8082
server:
port: 8080
spring:
profiles:
active: dev
---
server:
port: 8081
spring:
profiles:dev
---
server:
port: 8082
spring:
profiles:test
#配置文件到底可以写什么
SpringBoot使用一个全局配置文件,配置文件名字是固定的
SpringBoot有大量的配置,有的生效有的不生效,他通过这个注解来判断是否符合调减,符合条件就生效这个配置,我们可以通过自动装配注解来实现对应的自动装配。
在我们的配置文件中,能配置的东西都存在一个规律
他们一定会有个文件叫xxxProperties ,
在配置文件中添加:debug:true,在我们启动类之后会看到那些生效那些没生效,会以类似日志的方式输出
Positive matches:
已经自动装配并且生效的
negative matches:
没有生效的
总结: