A recent change in Spring Cloud Config 4.0.3 6ec9c432cb2c02840b85fdd8bcd0859eabc0ba46 now causes the ConfigClientProperties to bind before Spring Boot has loaded classpath:application.yml.

example/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>example-application</artifactId>
  <version>1.0-SNAPSHOT</version>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.0</version>
  </parent>

  <properties>
    <java.version>17</java.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>2022.0.3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

example/src/main/java/com/example/application/ExampleApplication.java

package com.example.application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(ExampleApplication.class, args);
    }
}

example/src/main/resources/application.yml

spring:
  cloud:
    config:
      label: customlabel

example/application.yml

spring:
  config:
    import: 'configserver:'

Running the example above will show the ConfigClientProperties bind with no property values, this works as expected in Spring Cloud Config 4.0.2.

TheConfigServerConfigDataLocationResolver.resolve() method now calls resolveProfileSpecific() and binds ConfigClientProperties while ConfigDataEnvironmentContributors are still processing.

Comment From: ryanjbaxter

This should be fixed by this PR https://github.com/spring-cloud/spring-cloud-config/pull/2275

Can you try 2022.0.4-SNAPSHOT and see if it works for you?

Comment From: meverden

Hello @ryanjbaxter,

I'm observing the following behavior with 2022.0.4-SNAPSHOT:

  1. ConfigServerConfigDataLocationResolver.loadProperties() binds ConfigClientProperties with the correct property values from classpath:application.yml.
  2. ConfigServerConfigDataLocationResolver.loadProperties() then crushing the property values with BeanUtils.copyProperties() from an empty bootstrap context ConfigClientProperties.
  3. ConfigServerConfigDataLoader.doLoad() referencing the empty ConfigClientProperties.

Comment From: ryanjbaxter

How are you telling Spring Boot to load example/application.yml?

Comment From: meverden

Hello @ryanjbaxter,

Using the example files posted above, I'm using the following to debug 2022.0.4-SNAPSHOT:

$ find . -type file 
./pom.xml
./application.yml
./src/main/resources/application.yml
./src/main/java/com/example/application/ExampleApplication.java

$ mvn clean package

$ java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 -jar target/example-application-1.0-SNAPSHOT.jar

I'm using the default Spring Boot External Config File locations, classpath root and current directory.

Let me know if you need any additional info.

Comment From: ryanjbaxter

Got it, thanks.

I think the fix here will address things https://github.com/spring-cloud/spring-cloud-config/pull/2282

Not sure if you are up for building my branch and giving it a try or not. If not no worries, you can wait for it to be merged and try snapshots.

Comment From: meverden

I'll take a look at the branch, and let you know what I find.

Comment From: meverden

Confirmed that ryanjbaxter:initialize-configclientpropertiesalways is working correctly with Spring Boot 2.6.14 and Spring Cloud 2021.0.8-SNAPSHOT.

I'll confirm Spring Boot 3.1.0 and Spring Cloud 2022.0.4-SNAPSHOT after the snapshot is updated.