Break circular dependency in DevTools without using field injection
This commit is contained in:
parent
06cf698387
commit
d0f329caa4
|
@ -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 {
|
||||||
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue