我有一个application.yml
文件,其中包含多个弹簧轮廓。
我想将属性从一个配置文件继承到另一个。
在此示例中,我想将prod概要文件的属性继承到prod1中,而无需再次在prod1概要文件中写入公共属性。
server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
application:
name: TestApp
URL: "https://localhost:8181/Services/IDEA-Client-Partners"
---
spring:
profiles: dev
---
spring:
profiles: prod
URL: https://www.ideaedu.org/Services/IDEA-Client-Partners
---
spring:
profiles: prod1
答案 0 :(得分:1)
属性确实已经继承。例如。如果您激活 给出您的示例, 并激活所有个人资料, 将设置以下属性, 如果属性冲突,例如在此示例中,prod
和prod1
,则所有默认 server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
application:
name: TestApp
URL: "https://localhost:8181/Services/IDEA-Client-Partners"
---
spring:
profiles: dev
---
spring:
profiles: prod
URL: https://www.ideaedu.org/Services/IDEA-Client-Partners
prodProperty: test
---
spring:
profiles: prod1
URL: https://localhost/
-Dspring.profiles.active=prod,prod1
URL
将赢得最后一个属性读取,即,当prod
和prod1
处于活动状态时,将读取最后一个属性,在这种情况下,将使用prod1
的定义。>