在Maven构建时将属性添加到Spring Boot application.yml文件

时间:2018-09-20 15:26:39

标签: maven spring-boot netflix-eureka spring-cloud-netflix spring-boot-maven-plugin

我有一个用例,我需要在maven构建时为每个Spring引导配置文件将一些属性写入spring boot application.yml文件。

Input(application.yml):

spring:
  profiles: ED

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-ed.aord.expertcity.com:8080/eureka/

---
spring:
  profiles: RC

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-rc.aord.expertcity.com:8080/eureka/

预期的输出(在Maven构建后为application.yml):

spring:
  profiles: ED

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      defaultZone: dummy-url-1,dummy-url-2
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-ed.aord.expertcity.com:8080/eureka/

---
spring:
  profiles: RC

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      defaultZone: dummy-url-1,dummy-url-2
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-rc.aord.expertcity.com:8080/eureka/ 

请注意预期输出中添加的行defaultZone: dummy-url-1,dummy-url-2。有没有可用的Maven插件来实现这一目标?

1 个答案:

答案 0 :(得分:1)

使用此answer

您应该安装Maven Resources Plugin,而${property.key}使用@property.key@。像这样:

us-west-2a: @eureka.environment@