默认配置文件
当我们创建一个springboot项目的时候,系统默认会为我们在src/main/Java/resources目录下创建一个application.properties。
springboot如何同时加载多个配置文件?
1. springboot 默认是在src/main/resources文件夹中加载application.properties默认配置文件
格式为application-{profile}.properties,其中{profile}对应你的环境标识
2. 在application.properties中添加spring.profiles.active = dev,database
# 加载多个配置文件,系统加载了application.properties application-database.properties application-dev.properties 三个配置文件
spring.profiles.active = dev,database
例如:加载application-goto配置文件
// application.yml
spring:
profiles:
active: dev,goto
// application-goto.yml
goto:
point:
organization: 12136
server:
url: http://12138:9010
取值方法一:
// 注入Environment
@Autowired
private Environment env;
...
// 取值
String s = env.getProperty("goto.point.organization");
...
本文详细介绍了SpringBoot中如何加载多个配置文件,包括默认配置文件的位置、如何激活特定环境的配置文件,以及如何在代码中获取这些配置文件中的属性值。
1570

被折叠的 条评论
为什么被折叠?



