2

我在 Spring Boot 应用程序中有此配置:

spring:
  application:
    name: my-app
  profiles:
    active: ${ENVIRONMENT}
  cloud:
    config:
     uri: http://localhost:8888

我的配置服务器读取以下文件:

我的应用程序 dev.yaml

prop: dev property

我的应用程序 pro.yaml

prop: pro property.

我启动 spring boot 应用程序设置-DENVIRONMENT=dev,正确加载 dev 外部 Git 属性。

当我在假设一个控制器中注入环境时,env.getActiveProfiles()我是否按预期获得了“开发”。

我想从 git 配置中添加更多配置文件。例如:

我的应用程序 dev.yaml

prop: dev property
spring:
  active:
    profiles: dev,business1

我的应用程序 pro.yaml

prop: dev property
spring:
  active:
    profiles: pro,business2

所以env.getActiveProfiles()返回["dev","business1"]。但是它返回的是初始的"dev".

怎么可能做到这一点?

更新:

正如 Dave Syer 所建议的,我尝试spring.profiles.include在 Git 文件中使用,但新配置文件未添加到环境中:

我的应用程序 dev.yaml

prop: dev property
spring:
  profiles:
    include: business1

我的应用程序 pro.yaml

prop: dev property
spring:
  profiles:
    include: business2

environment.getActiveProfiles() ---> "dev"

4

1 回答 1

2

将你的 spring-boot 更新到 1.5.4。

我在我的 Mac 上测试了相同的案例,我发现不同版本的 spring 表现不同。

当我将 Spring Boot 1.3.8.RELEASE 与 Spring Cloud Brixton.SR7 一起使用时,我将[dev]配置文件作为活动配置文件(也与 Spring Boot 1.4.5.RELEASE 一起使用)

当我将 Spring Boot 1.5.4.RELEASE 与 Spring Cloud Dalston.SR1 一起使用时,我将 [business1, dev]配置文件作为活动配置文件

所以我相信这是 Spring Boot 1.3.x 和 1.4.x 中的一个错误

于 2017-07-13T01:38:22.177 回答