Update LocalDevToolsAutoConfiguration to use constructor injection

Closes gh-11769
pull/11811/head
Stephane Nicoll 7 years ago
parent c533cb28bc
commit 90545fb0c6

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -62,11 +61,11 @@ public class LocalDevToolsAutoConfiguration {
@ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true)
static class LiveReloadConfiguration { static class LiveReloadConfiguration {
@Autowired private final DevToolsProperties properties;
private DevToolsProperties properties;
@Autowired(required = false) LiveReloadConfiguration(DevToolsProperties properties) {
private LiveReloadServer liveReloadServer; this.properties = properties;
}
@Bean @Bean
@RestartScope @RestartScope
@ -76,21 +75,16 @@ public class LocalDevToolsAutoConfiguration {
Restarter.getInstance().getThreadFactory()); Restarter.getInstance().getThreadFactory());
} }
@EventListener @Bean
public void onContextRefreshed(ContextRefreshedEvent event) { public OptionalLiveReloadServer optionalLiveReloadServer(
optionalLiveReloadServer().triggerReload(); LiveReloadServer liveReloadServer) {
} return new OptionalLiveReloadServer(liveReloadServer);
@EventListener
public void onClassPathChanged(ClassPathChangedEvent event) {
if (!event.isRestartRequired()) {
optionalLiveReloadServer().triggerReload();
}
} }
@Bean @Bean
public OptionalLiveReloadServer optionalLiveReloadServer() { public LiveReloadServerEventListener liveReloadServerEventListener(
return new OptionalLiveReloadServer(this.liveReloadServer); OptionalLiveReloadServer liveReloadServer) {
return new LiveReloadServerEventListener(liveReloadServer);
} }
} }
@ -102,8 +96,11 @@ public class LocalDevToolsAutoConfiguration {
@ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.devtools.restart", name = "enabled", matchIfMissing = true)
static class RestartConfiguration { static class RestartConfiguration {
@Autowired private final DevToolsProperties properties;
private DevToolsProperties properties;
RestartConfiguration(DevToolsProperties properties) {
this.properties = properties;
}
@EventListener @EventListener
public void onClassPathChanged(ClassPathChangedEvent event) { public void onClassPathChanged(ClassPathChangedEvent event) {
@ -164,4 +161,27 @@ public class LocalDevToolsAutoConfiguration {
} }
static class LiveReloadServerEventListener {
private final OptionalLiveReloadServer liveReloadServer;
LiveReloadServerEventListener(
OptionalLiveReloadServer liveReloadServer) {
this.liveReloadServer = liveReloadServer;
}
@EventListener
public void onContextRefreshed(ContextRefreshedEvent event) {
this.liveReloadServer.triggerReload();
}
@EventListener
public void onClassPathChanged(ClassPathChangedEvent event) {
if (!event.isRestartRequired()) {
this.liveReloadServer.triggerReload();
}
}
}
} }

Loading…
Cancel
Save