diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 762168d1e7..eb1fea5b62 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -131,6 +131,11 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, */ public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10; + /** + * Name of the application configuration {@link PropertySource}. + */ + public static final String APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME = "applicationConfigurationProperties"; + private final DeferredLog logger = new DeferredLog(); private String searchLocations; @@ -599,14 +604,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, static class ConfigurationPropertySources extends EnumerablePropertySource>> { - private static final String NAME = "applicationConfigurationProperties"; + private final Collection> sources; private final String[] names; ConfigurationPropertySources(Collection> sources) { - super(NAME, sources); + super(APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME, sources); this.sources = sources; List names = new ArrayList(); for (PropertySource source : sources) { @@ -630,9 +635,9 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, } public static void finishAndRelocate(MutablePropertySources propertySources) { + String name = APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME; ConfigurationPropertySources removed = (ConfigurationPropertySources) propertySources - .get(ConfigurationPropertySources.NAME); - String name = ConfigurationPropertySources.NAME; + .get(name); if (removed != null) { for (PropertySource propertySource : removed.sources) { if (propertySource instanceof EnumerableCompositePropertySource) { @@ -646,7 +651,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, propertySources.addAfter(name, propertySource); } } - propertySources.remove(ConfigurationPropertySources.NAME); + propertySources.remove(APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/RandomValuePropertySource.java b/spring-boot/src/main/java/org/springframework/boot/context/config/RandomValuePropertySource.java index f49c935f11..b1794c8e85 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/RandomValuePropertySource.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/RandomValuePropertySource.java @@ -51,6 +51,11 @@ import org.springframework.util.StringUtils; */ public class RandomValuePropertySource extends PropertySource { + /** + * Name of the random {@link PropertySource}. + */ + public static final String RANDOM_PROPERTY_SOURCE_NAME = "random"; + private static final String PREFIX = "random."; private static Log logger = LogFactory.getLog(RandomValuePropertySource.class); @@ -59,6 +64,10 @@ public class RandomValuePropertySource extends PropertySource { super(name, new Random()); } + public RandomValuePropertySource() { + this(RANDOM_PROPERTY_SOURCE_NAME); + } + @Override public Object getProperty(String name) { if (!name.startsWith(PREFIX)) { @@ -126,7 +135,7 @@ public class RandomValuePropertySource extends PropertySource { public static void addToEnvironment(ConfigurableEnvironment environment) { environment.getPropertySources().addAfter( StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, - new RandomValuePropertySource("random")); + new RandomValuePropertySource(RANDOM_PROPERTY_SOURCE_NAME)); logger.trace("RandomValuePropertySource add to Environment"); } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java index 6e53c108f5..b22e00c81a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,7 +126,7 @@ public class PropertiesConfigurationFactoryTests { MutablePropertySources propertySources = new MutablePropertySources(); propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment", Collections.singletonMap("FOO_BAR_NAME", "blah"))); - propertySources.addLast(new RandomValuePropertySource("random")); + propertySources.addLast(new RandomValuePropertySource()); setupFactory(); this.factory.setPropertySources(propertySources); this.factory.afterPropertiesSet(); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index f80bb9a015..3b64e4b5f2 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -519,7 +519,8 @@ public class ConfigFileApplicationListenerTests { assertThat(Arrays.asList(this.environment.getActiveProfiles()), contains("dev")); assertThat(property, equalTo("fromdevprofile")); ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment - .getPropertySources().get("applicationConfigurationProperties"); + .getPropertySources() + .get(ConfigFileApplicationListener.APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME); Collection> sources = propertySource .getSource(); assertEquals(2, sources.size()); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/RandomValuePropertySourceTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/RandomValuePropertySourceTests.java index 953add83b6..0d316c314b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/RandomValuePropertySourceTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/RandomValuePropertySourceTests.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue; */ public class RandomValuePropertySourceTests { - private RandomValuePropertySource source = new RandomValuePropertySource("random"); + private RandomValuePropertySource source = new RandomValuePropertySource(); @Test public void notRandom() {