diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java index d5e181b33f..df075273af 100755 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java @@ -20,7 +20,10 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.apache.commons.logging.Log; + import org.springframework.boot.SpringApplication; +import org.springframework.boot.devtools.logger.DevToolsLogFactory; import org.springframework.boot.devtools.restart.Restarter; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.Ordered; @@ -28,7 +31,6 @@ import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.PropertySource; /** * {@link EnvironmentPostProcessor} to add properties that make sense when working at @@ -42,33 +44,40 @@ import org.springframework.core.env.PropertySource; @Order(Ordered.LOWEST_PRECEDENCE) public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor { + private static final Log logger = DevToolsLogFactory + .getLog(DevToolsPropertyDefaultsPostProcessor.class); + + private static final String ENABLED = "spring.devtools.add-properties"; + private static final Map PROPERTIES; static { - Map devToolsProperties = new HashMap<>(); - devToolsProperties.put("spring.thymeleaf.cache", "false"); - devToolsProperties.put("spring.freemarker.cache", "false"); - devToolsProperties.put("spring.groovy.template.cache", "false"); - devToolsProperties.put("spring.mustache.cache", "false"); - devToolsProperties.put("server.servlet.session.persistent", "true"); - devToolsProperties.put("spring.h2.console.enabled", "true"); - devToolsProperties.put("spring.resources.cache.period", "0"); - devToolsProperties.put("spring.resources.chain.cache", "false"); - devToolsProperties.put("spring.template.provider.cache", "false"); - devToolsProperties.put("spring.mvc.log-resolved-exception", "true"); - devToolsProperties.put("server.error.include-stacktrace", "ALWAYS"); - devToolsProperties.put("server.servlet.jsp.init-parameters.development", "true"); - devToolsProperties.put("spring.reactor.stacktrace-mode.enabled", "true"); - PROPERTIES = Collections.unmodifiableMap(devToolsProperties); + Map properties = new HashMap<>(); + properties.put("spring.thymeleaf.cache", "false"); + properties.put("spring.freemarker.cache", "false"); + properties.put("spring.groovy.template.cache", "false"); + properties.put("spring.mustache.cache", "false"); + properties.put("server.servlet.session.persistent", "true"); + properties.put("spring.h2.console.enabled", "true"); + properties.put("spring.resources.cache.period", "0"); + properties.put("spring.resources.chain.cache", "false"); + properties.put("spring.template.provider.cache", "false"); + properties.put("spring.mvc.log-resolved-exception", "true"); + properties.put("server.error.include-stacktrace", "ALWAYS"); + properties.put("server.servlet.jsp.init-parameters.development", "true"); + properties.put("spring.reactor.stacktrace-mode.enabled", "true"); + properties.put("logging.level.web", "debug"); + PROPERTIES = Collections.unmodifiableMap(properties); } @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { if (isLocalApplication(environment) && canAddProperties(environment)) { - PropertySource propertySource = new MapPropertySource("refresh", - PROPERTIES); - environment.getPropertySources().addLast(propertySource); + logger.info("Devtools property and logging defaults active! Set '" + ENABLED + + "' to 'false' to disable"); + environment.getPropertySources() + .addLast(new MapPropertySource("devtools", PROPERTIES)); } } @@ -77,7 +86,10 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro } private boolean canAddProperties(Environment environment) { - return isRestarterInitialized() || isRemoteRestartEnabled(environment); + if (environment.getProperty(ENABLED, Boolean.class, true)) { + return isRestarterInitialized() || isRemoteRestartEnabled(environment); + } + return false; } private boolean isRestarterInitialized() { diff --git a/spring-boot-project/spring-boot-devtools/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-devtools/src/main/resources/META-INF/additional-spring-configuration-metadata.json index d68cdbc0e1..081c720427 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-devtools/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -19,6 +19,12 @@ "reason": "Remote debug is no longer supported.", "level": "error" } + }, + { + "name": "spring.devtools.add-properties", + "type": "java.lang.Boolean", + "description": "Whether to enable devtool property defaults.", + "defaultValue": true } ] -} \ No newline at end of file +} diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc index 42a1c3e120..1d3c879023 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc @@ -783,6 +783,16 @@ For example, Thymeleaf offers the `spring.thymeleaf.cache` property. Rather than to set these properties manually, the `spring-boot-devtools` module automatically applies sensible development-time configuration. +Because you need more information about web requests while developing Spring MVC and +Spring WebFlux applications, developer tools will enable `DEBUG` logging for the `web` +logging group. This will give you information about the incoming request, which handler is +processing it, the response outcome, etc. If you wish to log all request details +(including potentially sensitive information), you can turn on the +`spring.http.log-request-details` configuration property. + +NOTE: If you don't want property defaults to be applied you can set +`spring.devtools.add-properties` to `false` in your `application.properties`. + TIP: For a complete list of the properties that are applied by the devtools, see {sc-spring-boot-devtools}/env/DevToolsPropertyDefaultsPostProcessor.{sc-ext}[DevToolsPropertyDefaultsPostProcessor].