From 0693ec12b3d0f3ac9c055e5944c7604e401450b0 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 This commit changes the default value of configuration property `spring.devtools.livereload.enabled` to `false`. 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 173bf28d3810..4cc9d9d67857 100644 --- a/documentation/spring-boot-docs/build.gradle +++ b/documentation/spring-boot-docs/build.gradle @@ -320,7 +320,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 d1499cc6a235..9e3d688f11e9 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 6c5b1aaadf89..986dcd2367d7 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 static class Livereload { /** * 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 e71bbba62f1e..4392bf46eb4e 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 066ef65fc968..ef4f525f23d2 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 @@ private void logWarnings() { * 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 f0dafa7edf3e..fefd96f93299 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 @@ -111,16 +111,11 @@ void resourceCachePeriodIsZero() throws Exception { 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)); @@ -129,7 +124,9 @@ void liveReloadTriggeredOnContextRefresh() throws Exception { @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); @@ -139,7 +136,9 @@ void liveReloadTriggeredOnClassPathChangeWithoutRestart() throws Exception { @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); @@ -148,10 +147,8 @@ void liveReloadNotTriggeredOnClassPathChangeWithRestart() throws Exception { } @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(() -> 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 21899871f78a..12710134a99e 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 @@ -102,8 +102,8 @@ void failIfNoSecret() { } @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); this.clientContext.publishEvent(event); @@ -112,8 +112,8 @@ void liveReloadOnClassPathChanged() throws Exception { } @Test - void liveReloadDisabled() { - configure("spring.devtools.livereload.enabled:false"); + void liveReloadDisabledByDefault() { + configure(); assertThatExceptionOfType(NoSuchBeanDefinitionException.class) .isThrownBy(() -> this.context.getBean(OptionalLiveReloadServer.class)); }