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 <vedran@vedranpavic.com>
This commit is contained in:
Vedran Pavic
2025-10-20 18:10:47 -07:00
committed by Phillip Webb
parent 41a399c5ae
commit b3133d4ec1
7 changed files with 20 additions and 23 deletions
@@ -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.
@@ -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
@@ -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;
@@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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);
@@ -104,8 +104,8 @@ class RemoteClientConfigurationTests {
}
@Test
void liveReloadOnClassPathChanged() throws Exception {
configure();
void liveReloadOnClassPathChanged() {
configure("spring.devtools.livereload.enabled:true");
Set<ChangedFiles> 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));
}