Spring boot 使用单个属性文件继承Spring概要文件属性
我有一个Spring boot 使用单个属性文件继承Spring概要文件属性,spring-boot,yaml,Spring Boot,Yaml,我有一个application.yml文件,其中包含多个spring配置文件。 我想将属性从一个配置文件继承到另一个配置文件 在本例中,我希望将prod配置文件的属性继承到prod1中,而无需在prod1配置文件中再次写入公共属性 server: port: 8080 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver application: name: Tes
application.yml
文件,其中包含多个spring配置文件。
我想将属性从一个配置文件继承到另一个配置文件
在本例中,我希望将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
如果激活多个配置文件,则属性已继承。例如,如果您激活
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
将设置以下属性:
- 端口=8080
- 潜水员类名=com.mysql.cj.jdbc.Driver
- name=TestApp
- prodProperty=测试
- URL=
如果属性冲突,例如本例中的
URL
,则最后读取的属性获胜,即当prod
和prod1
处于活动状态时,最后读取的属性将进入,prod1
在这种情况下的定义。为什么每个配置文件不具有单独的属性文件和一个具有公共配置的基本属性文件?@Smajl因为我有这么多配置文件,如果我创建单独的属性文件,将有这么多文件。这就是为什么我创建了一个文件。