【发布时间】:2015-09-12 10:52:33
【问题描述】:
我想在 Spring Boot 中设置 3 个配置文件:生产、开发、使用外部配置文件进行测试。
应用类:
@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication.run( Application.class, args );
}
}
AppConfig 类:
@Configuration
@PropertySources({
@PropertySource("config/application.yml"),
@PropertySource(value = "file:${external.config}")
})
@ConfigurationProperties
public class AppConfig {
}
config/application.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"
【问题讨论】:
标签: java spring spring-boot spring-profiles spring-boot-actuator