From b3133d4ec1277b53cbee5c1d0585a481f940673d Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Wed, 1 Oct 2025 20:56:09 +0200 Subject: [PATCH] Disable LiveReload server by default Change the default value of the configuration property `spring.devtools.livereload.enabled` to `false`. See gh-47387 Signed-off-by: Vedran Pavic --- documentation/spring-boot-docs/build.gradle | 2 +- .../reference/pages/using/devtools.adoc | 2 +- .../autoconfigure/DevToolsProperties.java | 2 +- .../LocalDevToolsAutoConfiguration.java | 2 +- .../client/RemoteClientConfiguration.java | 2 +- .../LocalDevToolsAutoConfigurationTests.java | 25 ++++++++----------- .../RemoteClientConfigurationTests.java | 8 +++--- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/documentation/spring-boot-docs/build.gradle b/documentation/spring-boot-docs/build.gradle index 4ecbf36f0f6..096cf4de1e4 100644 --- a/documentation/spring-boot-docs/build.gradle +++ b/documentation/spring-boot-docs/build.gradle @@ -381,7 +381,7 @@ tasks.register("documentDevtoolsPropertyDefaults", org.springframework.boot.buil tasks.register("runRemoteSpringApplicationExample", org.springframework.boot.build.docs.ApplicationRunner) { classpath = configurations.remoteSpringApplicationExample mainClass = "org.springframework.boot.devtools.RemoteSpringApplication" - args = ["https://myapp.example.com", "--spring.devtools.remote.secret=secret", "--spring.devtools.livereload.port=0"] + args = ["https://myapp.example.com", "--spring.devtools.remote.secret=secret", "--spring.devtools.livereload.enabled=true", "--spring.devtools.livereload.port=0"] output = layout.buildDirectory.file("example-output/remote-spring-application.txt") expectedLogging = "Started RemoteSpringApplication in " applicationJar = "/Users/myuser/.m2/repository/org/springframework/boot/spring-boot-devtools/${project.version}/spring-boot-devtools-${project.version}.jar" diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/using/devtools.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/using/devtools.adoc index d1499cc6a23..9e3d688f11e 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/using/devtools.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/using/devtools.adoc @@ -287,7 +287,7 @@ The `spring-boot-devtools` module includes an embedded LiveReload server that ca LiveReload browser extensions are freely available for Chrome, Firefox and Safari. You can find these extensions by searching 'LiveReload' in the marketplace or store of your chosen browser. -If you do not want to start the LiveReload server when your application runs, you can set the configprop:spring.devtools.livereload.enabled[] property to `false`. +If you want to start the LiveReload server when your application runs, you can set the configprop:spring.devtools.livereload.enabled[] property to `true`. NOTE: You can only run one LiveReload server at a time. Before starting your application, ensure that no other LiveReload servers are running. diff --git a/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java b/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java index 6c5b1aaadf8..986dcd2367d 100644 --- a/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java +++ b/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java @@ -193,7 +193,7 @@ public class DevToolsProperties { /** * Whether to enable a livereload.com-compatible server. */ - private boolean enabled = true; + private boolean enabled = false; /** * Server port. diff --git a/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index e71bbba62f1..4392bf46eb4 100644 --- a/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -70,7 +70,7 @@ public final class LocalDevToolsAutoConfiguration { * Local LiveReload configuration. */ @Configuration(proxyBeanMethods = false) - @ConditionalOnBooleanProperty(name = "spring.devtools.livereload.enabled", matchIfMissing = true) + @ConditionalOnBooleanProperty(name = "spring.devtools.livereload.enabled") static class LiveReloadConfiguration { @Bean diff --git a/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java b/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java index 066ef65fc96..ef4f525f23d 100644 --- a/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java +++ b/module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java @@ -131,7 +131,7 @@ public class RemoteClientConfiguration implements InitializingBean { * LiveReload configuration. */ @Configuration(proxyBeanMethods = false) - @ConditionalOnBooleanProperty(name = "spring.devtools.livereload.enabled", matchIfMissing = true) + @ConditionalOnBooleanProperty(name = "spring.devtools.livereload.enabled") static class LiveReloadConfiguration { private final DevToolsProperties properties; diff --git a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index 454e7a4e00d..6d5ac1db909 100644 --- a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -112,16 +112,11 @@ class LocalDevToolsAutoConfigurationTests { assertThat(properties.getCache().getPeriod()).isZero(); } - @Test - void liveReloadServer() throws Exception { - this.context = getContext(() -> initializeAndRun(Config.class)); - LiveReloadServer server = this.context.getBean(LiveReloadServer.class); - assertThat(server.isStarted()).isTrue(); - } - @Test void liveReloadTriggeredOnContextRefresh() throws Exception { - this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class)); + Map properties = new HashMap<>(); + properties.put("spring.devtools.livereload.enabled", true); + this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class, properties)); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); this.context.publishEvent(new ContextRefreshedEvent(this.context)); @@ -130,7 +125,9 @@ class LocalDevToolsAutoConfigurationTests { @Test void liveReloadTriggeredOnClassPathChangeWithoutRestart() throws Exception { - this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class)); + Map properties = new HashMap<>(); + properties.put("spring.devtools.livereload.enabled", true); + this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class, properties)); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), false); @@ -140,7 +137,9 @@ class LocalDevToolsAutoConfigurationTests { @Test void liveReloadNotTriggeredOnClassPathChangeWithRestart() throws Exception { - this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class)); + Map properties = new HashMap<>(); + properties.put("spring.devtools.livereload.enabled", true); + this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class, properties)); LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), true); @@ -149,10 +148,8 @@ class LocalDevToolsAutoConfigurationTests { } @Test - void liveReloadDisabled() throws Exception { - Map properties = new HashMap<>(); - properties.put("spring.devtools.livereload.enabled", false); - this.context = getContext(() -> initializeAndRun(Config.class, properties)); + void liveReloadDisabledByDefault() throws Exception { + this.context = getContext(() -> initializeAndRun(Config.class)); assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> { assertThat(this.context).isNotNull(); this.context.getBean(OptionalLiveReloadServer.class); diff --git a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java index 8eab6adc02e..a1af0cd6d6a 100644 --- a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java +++ b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java @@ -104,8 +104,8 @@ class RemoteClientConfigurationTests { } @Test - void liveReloadOnClassPathChanged() throws Exception { - configure(); + void liveReloadOnClassPathChanged() { + configure("spring.devtools.livereload.enabled:true"); Set changeSet = new HashSet<>(); ClassPathChangedEvent event = new ClassPathChangedEvent(this, changeSet, false); assertThat(this.clientContext).isNotNull(); @@ -115,8 +115,8 @@ class RemoteClientConfigurationTests { } @Test - void liveReloadDisabled() { - configure("spring.devtools.livereload.enabled:false"); + void liveReloadDisabledByDefault() { + configure(); assertThatExceptionOfType(NoSuchBeanDefinitionException.class) .isThrownBy(() -> getContext().getBean(OptionalLiveReloadServer.class)); }