Enl*_*tMe 5 profile spring-boot
Spring Boot 属性文件是否可以依赖于两个或多个配置文件?就像是application-profile1-profile2.properties?
我知道的有4种方法。
插入.yaml或.properties以编程方式像 Asi Bross Said 一样。使用ResourceLoader或YamlPropertySourceLoader来插入。
使用.yaml。但当你有另一个 spring 项目依赖它时,它将被替换。
使用属性而不是配置文件。(对于api项目)
@PropertySource来定义属性文件 A。@PropertySource。例如:
resources
/-application.properties <-- remove or empty,because it will be override by application project
/-moduleA
/-application.properties <-- Intellij can identify properties files started with application-
/-application-mysql-dev.properties
/-application-psql-dev.properties
/-application-psql-prod.properties
Run Code Online (Sandbox Code Playgroud)
内容resources/moduleA/application.properties:
moduleA.custom.profile1=mysql
moduleA.custom.profile2=dev
Run Code Online (Sandbox Code Playgroud)
Java配置文件的内容:
resources
/-application.properties <-- remove or empty,because it will be override by application project
/-moduleA
/-application.properties <-- Intellij can identify properties files started with application-
/-application-mysql-dev.properties
/-application-psql-dev.properties
/-application-psql-prod.properties
Run Code Online (Sandbox Code Playgroud)
使用属性而不是配置文件。(针对申请项目)
resources
/-application.properties
/-application-mysql-dev.properties
/-application-psql-dev.properties
/-application-psql-prod.properties
Run Code Online (Sandbox Code Playgroud)
内容resources/application.properties:
moduleA.custom.profile1=mysql
moduleA.custom.profile2=dev
Run Code Online (Sandbox Code Playgroud)
内容SpringMvcApplication.java:
moduleA.custom.profile1=mysql
moduleA.custom.profile2=dev
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8683 次 |
| 最近记录: |