diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java index 7a6995e8..5f0e0e65 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java @@ -3,9 +3,11 @@ package org.springframework.cloud.client; import java.util.LinkedHashMap; import org.springframework.boot.SpringApplication; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.boot.context.config.ConfigFileApplicationListener; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.cloud.commons.util.InetUtils; import org.springframework.cloud.commons.util.InetUtils.HostInfo; @@ -34,7 +36,7 @@ public class HostInfoEnvironmentPostProcessor InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment); LinkedHashMap map = new LinkedHashMap<>(); map.put("spring.cloud.client.hostname", hostInfo.getHostname()); - map.put("spring.cloud.client.ipAddress", hostInfo.getIpAddress()); + map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress()); MapPropertySource propertySource = new MapPropertySource( "springCloudClientHostInfo", map); environment.getPropertySources().addLast(propertySource); @@ -42,9 +44,9 @@ public class HostInfoEnvironmentPostProcessor private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) { InetUtilsProperties target = new InetUtilsProperties(); - RelaxedDataBinder binder = new RelaxedDataBinder(target, - InetUtilsProperties.PREFIX); - binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); + new Binder(ConfigurationPropertySources.attach(environment.getPropertySources()), + new PropertySourcesPlaceholdersResolver(environment)) + .bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target)); try (InetUtils utils = new InetUtils(target)) { return utils.findFirstNonLoopbackHostInfo(); } diff --git a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessorTests.java b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessorTests.java index 0aaa1bac..6b9b2288 100644 --- a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessorTests.java +++ b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessorTests.java @@ -42,7 +42,7 @@ public class HostInfoEnvironmentPostProcessorTests { public void ipAddress() { this.processor.postProcessEnvironment(this.environment, new SpringApplication("")); - String address = this.environment.getProperty("spring.cloud.client.ipAddress"); + String address = this.environment.getProperty("spring.cloud.client.ip-address"); assertNotNull(address); } diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java index 0d117af4..889b9c7d 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java @@ -27,10 +27,11 @@ import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.boot.context.config.ConfigFileApplicationListener; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.logging.LogFile; import org.springframework.boot.logging.LoggingInitializationContext; import org.springframework.boot.logging.LoggingSystem; @@ -153,8 +154,8 @@ public class PropertySourceBootstrapConfiguration implements MutablePropertySources incoming = new MutablePropertySources(); incoming.addFirst(composite); PropertySourceBootstrapProperties remoteProperties = new PropertySourceBootstrapProperties(); - new RelaxedDataBinder(remoteProperties, "spring.cloud.config") - .bind(new PropertySourcesPropertyValues(incoming)); + new Binder(ConfigurationPropertySources.attach(incoming)) + .bind("spring.cloud.config", Bindable.ofInstance(remoteProperties)); if (!remoteProperties.isAllowOverride() || (!remoteProperties.isOverrideNone() && remoteProperties.isOverrideSystemProperties())) { propertySources.addFirst(composite); diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java index 3ea5444f..2a1a7f04 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java @@ -25,7 +25,6 @@ import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -46,6 +45,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.springframework.boot.WebApplicationType.NONE; /** * @author Dave Syer @@ -80,7 +80,7 @@ public class BootstrapConfigurationTests { public void pickupExternalBootstrapProperties() { String externalPropertiesPath = getExternalProperties(); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class) .properties("spring.cloud.bootstrap.location:" + externalPropertiesPath) .run(); @@ -92,7 +92,7 @@ public class BootstrapConfigurationTests { @Test public void bootstrapPropertiesAvailableInInitializer() { - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).initializers( new ApplicationContextInitializer() { @Override @@ -123,7 +123,7 @@ public class BootstrapConfigurationTests { } else { externalProperties = new File( - "spring-cloud-config-client/src/test/resources/external-properties/bootstrap.properties"); + "spring-cloud-context/src/test/resources/external-properties/bootstrap.properties"); externalPropertiesPath = externalProperties.getAbsolutePath(); } return externalPropertiesPath; @@ -132,7 +132,7 @@ public class BootstrapConfigurationTests { @Test public void picksUpAdditionalPropertySource() { PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).run(); assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo")); assertTrue(this.context.getEnvironment().getPropertySources().contains( @@ -143,7 +143,7 @@ public class BootstrapConfigurationTests { public void failsOnPropertySource() { System.setProperty("expected.fail", "true"); this.expected.expectMessage("Planned"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).run(); } @@ -151,7 +151,7 @@ public class BootstrapConfigurationTests { public void overrideSystemPropertySourceByDefault() { PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar"); System.setProperty("bootstrap.foo", "system"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).run(); assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo")); } @@ -162,7 +162,7 @@ public class BootstrapConfigurationTests { PropertySourceConfiguration.MAP .put("spring.cloud.config.overrideSystemProperties", "false"); System.setProperty("bootstrap.foo", "system"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).run(); assertEquals("system", this.context.getEnvironment().getProperty("bootstrap.foo")); @@ -178,7 +178,7 @@ public class BootstrapConfigurationTests { // their own remote property source. PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "false"); System.setProperty("bootstrap.foo", "system"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).run(); assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo")); } @@ -190,7 +190,7 @@ public class BootstrapConfigurationTests { .put("spring.cloud.config.overrideSystemProperties", "false"); PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "true"); System.setProperty("bootstrap.foo", "system"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .sources(BareConfiguration.class).run(); assertEquals("system", this.context.getEnvironment().getProperty("bootstrap.foo")); @@ -204,7 +204,7 @@ public class BootstrapConfigurationTests { ConfigurableEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addLast(new MapPropertySource("last", Collections.singletonMap("bootstrap.foo", "splat"))); - this.context = new SpringApplicationBuilder().web(false).environment(environment) + this.context = new SpringApplicationBuilder().web(NONE).environment(environment) .sources(BareConfiguration.class).run(); assertEquals("splat", this.context.getEnvironment().getProperty("bootstrap.foo")); } @@ -212,7 +212,7 @@ public class BootstrapConfigurationTests { @Test public void applicationNameInBootstrapAndMain() { System.setProperty("expected.name", "main"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .properties("spring.cloud.bootstrap.name:other", "spring.config.name:plain") .sources(BareConfiguration.class).run(); @@ -232,7 +232,7 @@ public class BootstrapConfigurationTests { @Test public void applicationNameNotInBootstrap() { System.setProperty("expected.name", "main"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .properties("spring.cloud.bootstrap.name:application", "spring.config.name:other") .sources(BareConfiguration.class).run(); @@ -247,7 +247,7 @@ public class BootstrapConfigurationTests { @Test public void applicationNameOnlyInBootstrap() { System.setProperty("expected.name", "main"); - this.context = new SpringApplicationBuilder().web(false) + this.context = new SpringApplicationBuilder().web(NONE) .properties("spring.cloud.bootstrap.name:other") .sources(BareConfiguration.class).run(); // The main context is called "main" because spring.application.name is specified @@ -266,7 +266,7 @@ public class BootstrapConfigurationTests { PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar"); this.context = new SpringApplicationBuilder().sources(BareConfiguration.class) .environment(new StandardEnvironment()).child(BareConfiguration.class) - .web(false).run(); + .web(NONE).run(); assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo")); assertEquals(this.context.getEnvironment(), this.context.getParent().getEnvironment()); @@ -283,7 +283,7 @@ public class BootstrapConfigurationTests { TestHigherPriorityBootstrapConfiguration.count.set(0); PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar"); this.context = new SpringApplicationBuilder().sources(BareConfiguration.class) - .child(BareConfiguration.class).web(false).run(); + .child(BareConfiguration.class).web(NONE).run(); assertEquals(1, TestHigherPriorityBootstrapConfiguration.count.get()); assertNotNull(context.getParent()); assertEquals("bootstrap", context.getParent().getParent().getId()); @@ -298,9 +298,9 @@ public class BootstrapConfigurationTests { SpringApplicationBuilder builder = new SpringApplicationBuilder() .sources(BareConfiguration.class); this.sibling = builder.child(BareConfiguration.class) - .properties("spring.application.name=sibling").web(false).run(); + .properties("spring.application.name=sibling").web(NONE).run(); this.context = builder.child(BareConfiguration.class) - .properties("spring.application.name=context").web(false).run(); + .properties("spring.application.name=context").web(NONE).run(); assertEquals(1, TestHigherPriorityBootstrapConfiguration.count.get()); assertNotNull(context.getParent()); assertEquals("bootstrap", context.getParent().getParent().getId()); @@ -320,7 +320,7 @@ public class BootstrapConfigurationTests { public void environmentEnrichedInParentContext() { PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar"); this.context = new SpringApplicationBuilder().sources(BareConfiguration.class) - .child(BareConfiguration.class).web(false).run(); + .child(BareConfiguration.class).web(NONE).run(); assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo")); assertNotSame(this.context.getEnvironment(), this.context.getParent().getEnvironment()); @@ -336,9 +336,9 @@ public class BootstrapConfigurationTests { PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar"); // Profiles are always merged with the child ConfigurableApplicationContext parent = new SpringApplicationBuilder() - .sources(BareConfiguration.class).profiles("parent").web(false).run(); + .sources(BareConfiguration.class).profiles("parent").web(NONE).run(); this.context = new SpringApplicationBuilder(BareConfiguration.class) - .profiles("child").parent(parent).web(false).run(); + .profiles("child").parent(parent).web(NONE).run(); assertNotSame(this.context.getEnvironment(), this.context.getParent().getEnvironment()); // The ApplicationContext merges profiles (profiles and property sources), see @@ -364,7 +364,7 @@ public class BootstrapConfigurationTests { @Test public void includeProfileFromBootstrapPropertySource() { PropertySourceConfiguration.MAP.put("spring.profiles.include", "bar,baz"); - this.context = new SpringApplicationBuilder().web(false).profiles("foo") + this.context = new SpringApplicationBuilder().web(NONE).profiles("foo") .sources(BareConfiguration.class).run(); assertTrue(this.context.getEnvironment().acceptsProfiles("baz")); assertTrue(this.context.getEnvironment().acceptsProfiles("bar"));