Skip to content

Commit eabed25

Browse files
refactor: FileSystemWatcher bean configuration
1 parent c7e0a47 commit eabed25

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ public static class Livereload {
204204
*/
205205
private List<File> additionalPaths = new ArrayList<>();
206206

207+
/**
208+
* Amount of time to wait between polling for classpath changes.
209+
*/
210+
private Duration pollInterval = Duration.ofSeconds(1);
211+
212+
/**
213+
* Amount of quiet time required without any classpath changes before a reload is
214+
* triggered.
215+
*/
216+
private Duration quietPeriod = Duration.ofMillis(400);
217+
207218
public boolean isEnabled() {
208219
return this.enabled;
209220
}
@@ -228,6 +239,22 @@ public void setAdditionalPaths(List<File> additionalPaths) {
228239
this.additionalPaths = additionalPaths;
229240
}
230241

242+
public Duration getPollInterval() {
243+
return this.pollInterval;
244+
}
245+
246+
public void setPollInterval(Duration pollInterval) {
247+
this.pollInterval = pollInterval;
248+
}
249+
250+
public Duration getQuietPeriod() {
251+
return this.quietPeriod;
252+
}
253+
254+
public void setQuietPeriod(Duration quietPeriod) {
255+
this.quietPeriod = quietPeriod;
256+
}
257+
231258
}
232259

233260
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.beans.factory.DisposableBean;
2727
import org.springframework.boot.autoconfigure.AutoConfiguration;
2828
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
29+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2930
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3031
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3132
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -99,7 +100,14 @@ LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveR
99100
}
100101

101102
@Bean
102-
FileSystemWatcher fileSystemWatcher(DevToolsProperties properties, RestartConfiguration restartConfiguration) {
103+
@ConditionalOnMissingBean(RestartConfiguration.class)
104+
FileSystemWatcher newFileSystemWatcher(DevToolsProperties properties) {
105+
return new FileSystemWatcher(true, properties.getLivereload().getPollInterval(), properties.getLivereload().getQuietPeriod());
106+
}
107+
108+
@Bean
109+
@ConditionalOnBean(RestartConfiguration.class)
110+
FileSystemWatcher fileSystemWatcher(RestartConfiguration restartConfiguration) {
103111
return restartConfiguration.newFileSystemWatcher();
104112
}
105113

0 commit comments

Comments
 (0)