Home > Software design >  What are the proper changes for spring-cloud-config on Spring Boot 2.4.x?
What are the proper changes for spring-cloud-config on Spring Boot 2.4.x?

Time:11-20

I have been digging through the documentation for hours and can still not make sense of what actually needs to change in the web app I'm working on. In the original, pre 2.4.x version application.yml and application-local.yml do not have any cloud config related properties

All of the cloud config stuff is in bootstrap.yml divided into documents for generic and then environments:

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
---

Switching spring.profiles: int to spring.config.activate.on-profile: int in bootstrap.yml was simple enough to figure out. What I can't manage to find is what else I need to add (and where) to allow the config to be read from the server properly. I tried adding variations of spring.config.import: "optional:configserver:" to application.yml and while they have solved the error about that property being missing, none of them have allowed the values to be found. (I tried "configserver:", "configserver:https://my.local.server", & "optional:configserver:https://my.local.server")

I'm sure I'm missing something totally obvious, but I have no idea what it could be.

CodePudding user response:

You need to get rid of bootstrap.yml and put every property in application.yml. Something along the following lines:

(...)

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
---

(...)

Additionally, for Spring Boot. 2.4.6, make sure you have the following dependencies:

<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>
  • Related