diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java index 9a19bd4679f..acda258670c 100755 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java @@ -22,6 +22,8 @@ import java.util.Map; import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; @@ -34,6 +36,7 @@ import org.springframework.core.env.PropertySource; * @author Andy Wilkinson * @since 1.3.0 */ +@Order(Ordered.LOWEST_PRECEDENCE) public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor { private static final Map PROPERTIES; @@ -56,7 +59,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro if (isLocalApplication(environment)) { PropertySource propertySource = new MapPropertySource("refresh", PROPERTIES); - environment.getPropertySources().addFirst(propertySource); + environment.getPropertySources().addLast(propertySource); } } diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index 64f1f830af3..f52e554ab73 100755 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -90,6 +90,30 @@ public class LocalDevToolsAutoConfigurationTests { assertThat(resolver.isCacheable(), equalTo(false)); } + @Test + public void defaultPropertyCanBeOverridenFromCommandLine() throws Exception { + this.context = initializeAndRun(Config.class, "--spring.thymeleaf.cache=true"); + TemplateResolver resolver = this.context.getBean(TemplateResolver.class); + resolver.initialize(); + assertThat(resolver.isCacheable(), equalTo(true)); + } + + @Test + public void defaultPropertyCanBeOverridenFromUserHomeProperties() throws Exception { + String userHome = System.getProperty("user.home"); + System.setProperty("user.home", + new File("src/test/resources/user-home").getAbsolutePath()); + try { + this.context = initializeAndRun(Config.class); + TemplateResolver resolver = this.context.getBean(TemplateResolver.class); + resolver.initialize(); + assertThat(resolver.isCacheable(), equalTo(true)); + } + finally { + System.setProperty("user.home", userHome); + } + } + @Test public void resourceCachePeriodIsZero() throws Exception { this.context = initializeAndRun(WebResourcesConfig.class); @@ -210,17 +234,18 @@ public class LocalDevToolsAutoConfigurationTests { assertThat(folders, hasKey(new File("src/test/java").getAbsoluteFile())); } - private ConfigurableApplicationContext initializeAndRun(Class config) { - return initializeAndRun(config, Collections.emptyMap()); + private ConfigurableApplicationContext initializeAndRun(Class config, + String... args) { + return initializeAndRun(config, Collections.emptyMap(), args); } private ConfigurableApplicationContext initializeAndRun(Class config, - Map properties) { + Map properties, String... args) { Restarter.initialize(new String[0], false, new MockRestartInitializer(), false); SpringApplication application = new SpringApplication(config); application.setDefaultProperties(getDefaultProperties(properties)); application.setWebEnvironment(false); - ConfigurableApplicationContext context = application.run(); + ConfigurableApplicationContext context = application.run(args); return context; }