我想在 Spring Boot 中设置 3 个配置文件:使用外部配置文件进行生产、开发、测试。
应用类:
@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication.run( Application.class, args );
}
}
应用配置类:
@Configuration
@PropertySources({
@PropertySource("config/application.yml"),
@PropertySource(value = "file:${external.config}")
})
@ConfigurationProperties
public class AppConfig {
}
配置/应用程序.yml:
---
spring.profiles: production
endpoints.enabled: false
---
spring.profiles: development,test
endpoints.enabled: true
info.version: @project.version@
info.test: Test dev or test
info.profile: ${spring.profiles.active}
---
external.config: ${user.home}/.myapp/application.properties
.myapp/application.properties:
spring.profiles.active=production
info.version=5
spring-boot-actuator /info 的输出
{
version: "5",
test: "Test dev or test",
profile: "production"
}
预期输出:
404 because of the endpoints.enabled: false
spring-boot-actuator /env
spring.profiles.active: "production"