diff --git a/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy b/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy index 2ec3c2a7..2a857581 100644 --- a/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy +++ b/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy @@ -23,7 +23,6 @@ class Tracker { private static Core core private static TrackerService trackerService - private static WebServerCustomizer wsCustomizer public static void main(String [] args) { println "Launching MuWire Tracker version $VERSION" @@ -69,8 +68,8 @@ class Tracker { // json rcp props go in tracker.properties def jsonProps = new Properties() - jsonProps['jsonrpc.iface'] = props['jsonrpc.iface'] - jsonProps['jsonrpc.port'] = props['jsonrpc.port'] + jsonProps['tracker.jsonRpc.iface'] = props['jsonrpc.iface'] + jsonProps['tracker.jsonRpc.port'] = props['jsonrpc.port'] trackerProps.withPrintWriter { jsonProps.store(it, "") } } @@ -81,11 +80,6 @@ class Tracker { p = new Properties() trackerProps.withInputStream { p.load(it) } - InetAddress toBind = InetAddress.getByName(p['jsonrpc.iface']) - int port = Integer.parseInt(p['jsonrpc.port']) - - wsCustomizer = new WebServerCustomizer(toBind, port) - core = new Core(muSettings, home, VERSION) @@ -100,26 +94,9 @@ class Tracker { core.eventBus.publish(new UILoadedEvent()) } as Runnable) coreStarter.start() - - SpringApplication.run(Tracker.class, args) - } - - private static class WebServerCustomizer implements WebServerFactoryCustomizer { - - private final InetAddress toBind - private final int port - - WebServerCustomizer(InetAddress toBind, int port) { - this.toBind = toBind - this.port = port - } - @Override - public void customize(ConfigurableWebServerFactory factory) { - factory.setPort(port) - factory.setAddress(toBind) - } - + System.setProperty("spring.config.location", trackerProps.getAbsolutePath()) + SpringApplication.run(Tracker.class, args) } @Bean @@ -127,11 +104,6 @@ class Tracker { core } - @Bean - WebServerFactoryCustomizer wsCustomizer() { - wsCustomizer - } - @Bean public TrackerService trackerService() { trackerService diff --git a/tracker/src/main/groovy/com/muwire/tracker/TrackerProperties.groovy b/tracker/src/main/groovy/com/muwire/tracker/TrackerProperties.groovy new file mode 100644 index 00000000..76b1547f --- /dev/null +++ b/tracker/src/main/groovy/com/muwire/tracker/TrackerProperties.groovy @@ -0,0 +1,16 @@ +package com.muwire.tracker + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.stereotype.Component + +@Component +@ConfigurationProperties("tracker") +class TrackerProperties { + + final JsonRpc jsonRpc = new JsonRpc() + + public static class JsonRpc { + InetAddress iface + int port + } +} diff --git a/tracker/src/main/groovy/com/muwire/tracker/WebServerConfiguration.groovy b/tracker/src/main/groovy/com/muwire/tracker/WebServerConfiguration.groovy new file mode 100644 index 00000000..5feebb3f --- /dev/null +++ b/tracker/src/main/groovy/com/muwire/tracker/WebServerConfiguration.groovy @@ -0,0 +1,20 @@ +package com.muwire.tracker + +import org.springframework.boot.web.server.ConfigurableWebServerFactory +import org.springframework.boot.web.server.WebServerFactoryCustomizer +import org.springframework.stereotype.Component + +@Component +class WebServerConfiguration implements WebServerFactoryCustomizer { + + private final TrackerProperties trackerProperties + + WebServerConfiguration(TrackerProperties trackerProperties) { + this.trackerProperties = trackerProperties; + } + @Override + public void customize(ConfigurableWebServerFactory factory) { + factory.setAddress(trackerProperties.jsonRpc.getIface()) + factory.setPort(trackerProperties.jsonRpc.port) + } +}