Commit d0f329ca authored by Andy Wilkinson's avatar Andy Wilkinson

Break circular dependency in DevTools without using field injection

parent 06cf6983
...@@ -62,24 +62,12 @@ public class LocalDevToolsAutoConfiguration { ...@@ -62,24 +62,12 @@ 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 {
private DevToolsProperties properties;
private LiveReloadServer liveReloadServer; private LiveReloadServer liveReloadServer;
LiveReloadConfiguration(DevToolsProperties properties, LiveReloadConfiguration(ObjectProvider<LiveReloadServer> liveReloadServer) {
ObjectProvider<LiveReloadServer> liveReloadServer) {
this.properties = properties;
this.liveReloadServer = liveReloadServer.getIfAvailable(); this.liveReloadServer = liveReloadServer.getIfAvailable();
} }
@Bean
@RestartScope
@ConditionalOnMissingBean
public LiveReloadServer liveReloadServer() {
return new LiveReloadServer(this.properties.getLivereload().getPort(),
Restarter.getInstance().getThreadFactory());
}
@EventListener @EventListener
public void onContextRefreshed(ContextRefreshedEvent event) { public void onContextRefreshed(ContextRefreshedEvent event) {
optionalLiveReloadServer().triggerReload(); optionalLiveReloadServer().triggerReload();
...@@ -97,6 +85,19 @@ public class LocalDevToolsAutoConfiguration { ...@@ -97,6 +85,19 @@ public class LocalDevToolsAutoConfiguration {
return new OptionalLiveReloadServer(this.liveReloadServer); return new OptionalLiveReloadServer(this.liveReloadServer);
} }
@Configuration
static class LiveReloadServerConfiguration {
@Bean
@RestartScope
@ConditionalOnMissingBean
public LiveReloadServer liveReloadServer(DevToolsProperties properties) {
return new LiveReloadServer(properties.getLivereload().getPort(),
Restarter.getInstance().getThreadFactory());
}
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment