我已經研究了幾個小時的檔案,但仍然無法理解我正在處理的 Web 應用程式中實際需要更改的內容。在原始版本中,2.4.x 之前的版本application.yml并application-local.yml沒有任何與云配置相關的屬性
所有的云配置內容都bootstrap.yml分為通用檔案和環境檔案:
spring:
application:
name: my_app
cloud:
config:
label: develop
uri: https://my.local.server
username: user
password: password
enabled: true
---
spring:
profiles: int
cloud:
config:
label: develop
uri: https://my.int.server
username: user
password: password
enabled: true
---
…
切換spring.profiles: int到spring.config.activate.on-profile: intinbootstrap.yml很容易弄清楚。我無法找到的是我還需要添加什么(以及在哪里)以允許從服務器正確讀取配置。我嘗試添加spring.config.import: "optional:configserver:"to 的變體,application.yml雖然他們解決了有關該屬性丟失的錯誤,但他們都不允許找到這些值。(我試過"configserver:", "configserver:https://my.local.server", & "optional:configserver:https://my.local.server")
我確定我遺漏了一些非常明顯的東西,但我不知道它可能是什么。
uj5u.com熱心網友回復:
您需要擺脫bootstrap.yml并將所有屬性放入application.yml. 大致如下:
(...)
spring:
application:
name: my_app
cloud:
config:
label: develop
uri: https://my.local.server
username: user
password: password
enabled: true
---
spring:
config:
activate:
on-profile: int
cloud:
config:
label: develop
uri: https://my.int.server
username: user
password: password
enabled: true
---
(...)
此外,對于 Spring Boot。2.4.6、確保你有以下依賴:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-dependencies</artifactId>
<version>3.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/360873.html
