Browse Source

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>
pull/47721/head
Vedran Pavic 4 months ago committed by Phillip Webb
parent
commit
b3133d4ec1
  1. 2
      documentation/spring-boot-docs/build.gradle
  2. 2
      documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/using/devtools.adoc
  3. 2
      module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java
  4. 2
      module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java
  5. 2
      module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java
  6. 25
      module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java
  7. 8
      module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java

2
documentation/spring-boot-docs/build.gradle

@ -381,7 +381,7 @@ tasks.register("documentDevtoolsPropertyDefaults", org.springframework.boot.buil @@ -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"

2
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 @@ -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.

2
module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java

@ -193,7 +193,7 @@ public class DevToolsProperties { @@ -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.

2
module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java

@ -70,7 +70,7 @@ public final class LocalDevToolsAutoConfiguration { @@ -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

2
module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java

@ -131,7 +131,7 @@ public class RemoteClientConfiguration implements InitializingBean { @@ -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;

25
module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java

@ -112,16 +112,11 @@ class LocalDevToolsAutoConfigurationTests { @@ -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 { @@ -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 { @@ -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 { @@ -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);

8
module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java

@ -104,8 +104,8 @@ class RemoteClientConfigurationTests { @@ -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 { @@ -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));
}

Loading…
Cancel
Save