Allow default DevTools properties to be overridden
Previously the default DevTools property source was added in first place to the environment’s property sources in an unordered environment post-processor. This made it difficult to override them. This commit updates the post-processor to be ordered with lowest precedence and to add the property source in last place. This should allow any other property sources and to override the defaults. Closes gh-3851
This commit is contained in:
@@ -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.<String, Object>emptyMap());
|
||||
private ConfigurableApplicationContext initializeAndRun(Class<?> config,
|
||||
String... args) {
|
||||
return initializeAndRun(config, Collections.<String, Object>emptyMap(), args);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext initializeAndRun(Class<?> config,
|
||||
Map<String, Object> properties) {
|
||||
Map<String, Object> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user