Ensure config server works with Spring Boot 2.4

Since 2.4 the names of property sources have changed, so we have to
change the `clean()` method in `NativeEnvironmentRepository` in order
not to simply omit all the sources.
This commit is contained in:
Dave Syer
2020-12-11 12:03:00 +00:00
parent d89199d98a
commit 8b48ed36c6
2 changed files with 13 additions and 0 deletions

View File

@@ -231,6 +231,7 @@ public class NativeEnvironmentRepository implements EnvironmentRepository, Searc
}
// TODO: needed anymore?
name = name.replace("applicationConfig: [", "");
name = name.replace("file [", "");
name = name.replace("]", "");
if (this.searchLocations != null) {
boolean matches = false;

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.config.server.environment;
import java.util.Collections;
import java.util.regex.Matcher;
import org.junit.Before;
@@ -25,6 +26,7 @@ import org.junit.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.server.environment.SearchPathLocator.Locations;
import org.springframework.context.ConfigurableApplicationContext;
@@ -90,6 +92,16 @@ public class NativeEnvironmentRepositoryTests {
assertThat(environment.getVersion()).as("version was wrong").isEqualTo("myversion");
}
@Test
public void cleanBoot24() {
Environment environment = new Environment("application");
environment.add(new PropertySource(
"Config resource 'file [/tmp/config-repo-7780026223759117699/application-dev.yml]' via location 'file:/tmp/config-repo-7780026223759117699/'",
Collections.singletonMap("foo", "bar")));
assertThat(environment.getPropertySources().size()).isEqualTo(1);
assertThat(environment.getPropertySources().get(0).getName().contains("application-dev.yml"));
}
@Test
@Ignore // FIXME: configdata
public void labelled() {