Allow modules to contribute to Devtools' default properties

Closes gh-44792
This commit is contained in:
Andy Wilkinson
2025-10-15 20:19:02 +01:00
parent aab6375702
commit 55e7c83498
20 changed files with 112 additions and 84 deletions
@@ -16,12 +16,8 @@
package org.springframework.boot.devtools.env;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.jspecify.annotations.Nullable;
@@ -30,6 +26,7 @@ import org.springframework.boot.EnvironmentPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.devtools.logger.DevToolsLogFactory;
import org.springframework.boot.devtools.restart.Restarter;
import org.springframework.boot.devtools.settings.DevToolsSettings;
import org.springframework.boot.devtools.system.DevToolsEnablementDeducer;
import org.springframework.core.NativeDetector;
import org.springframework.core.Ordered;
@@ -69,7 +66,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
PROPERTIES = Collections.emptyMap();
}
else {
PROPERTIES = loadDefaultProperties();
PROPERTIES = DevToolsSettings.get().getPropertyDefaults();
}
}
@@ -133,24 +130,4 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
}
}
private static Map<String, Object> loadDefaultProperties() {
Properties properties = new Properties();
try (InputStream stream = DevToolsPropertyDefaultsPostProcessor.class
.getResourceAsStream("devtools-property-defaults.properties")) {
if (stream == null) {
throw new RuntimeException(
"Failed to load devtools-property-defaults.properties because it doesn't exist");
}
properties.load(stream);
}
catch (IOException ex) {
throw new RuntimeException("Failed to load devtools-property-defaults.properties", ex);
}
Map<String, Object> map = new HashMap<>();
for (String name : properties.stringPropertyNames()) {
map.put(name, properties.getProperty(name));
}
return Collections.unmodifiableMap(map);
}
}
@@ -18,7 +18,9 @@ package org.springframework.boot.devtools.settings;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -52,14 +54,23 @@ public class DevToolsSettings {
private final List<Pattern> restartExcludePatterns = new ArrayList<>();
private final Map<String, Object> propertyDefaults = new HashMap<>();
DevToolsSettings() {
}
void add(Map<?, ?> properties) {
private void add(Map<?, ?> properties) {
Map<String, Pattern> includes = getPatterns(properties, "restart.include.");
this.restartIncludePatterns.addAll(includes.values());
Map<String, Pattern> excludes = getPatterns(properties, "restart.exclude.");
this.restartExcludePatterns.addAll(excludes.values());
properties.forEach((key, value) -> {
String name = String.valueOf(key);
if (name.startsWith("defaults.")) {
name = name.substring("defaults.".length());
this.propertyDefaults.put(name, value);
}
});
}
private Map<String, Pattern> getPatterns(Map<?, ?> properties, String prefix) {
@@ -82,6 +93,10 @@ public class DevToolsSettings {
return isMatch(url.toString(), this.restartExcludePatterns);
}
public Map<String, Object> getPropertyDefaults() {
return Collections.unmodifiableMap(this.propertyDefaults);
}
private boolean isMatch(String url, List<Pattern> patterns) {
for (Pattern pattern : patterns) {
if (pattern.matcher(url).find()) {
@@ -1,17 +0,0 @@
server.error.include-binding-errors=always
server.error.include-message=always
server.error.include-stacktrace=always
server.servlet.jsp.init-parameters.development=true
server.servlet.session.persistent=true
spring.freemarker.cache=false
spring.graphql.graphiql.enabled=true
spring.groovy.template.cache=false
spring.h2.console.enabled=true
spring.mustache.servlet.cache=false
spring.mvc.log-resolved-exception=true
spring.reactor.netty.shutdown-quiet-period=0s
spring.template.provider.cache=false
spring.thymeleaf.cache=false
spring.web.resources.cache.period=0
spring.web.resources.chain.cache=false
spring.docker.compose.readiness.wait=only-if-started