org.zodiac.autoconfigure.bootstrap.discovery.simple.SimpleAppDiscoveryClientAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.bootstrap.discovery.simple;
import java.net.URI;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnAppDiscoveryEnabled;
import org.zodiac.autoconfigure.bootstrap.discovery.AbstractAppDiscoveryClientConfiguration;
import org.zodiac.commons.util.Networks;
import org.zodiac.core.bootstrap.discovery.AppDiscoveryClient;
import org.zodiac.sdk.toolkit.util.ProtocolScheme;
@SpringBootConfiguration
@ConditionalOnAppDiscoveryEnabled
public class SimpleAppDiscoveryClientAutoConfiguration extends AbstractAppDiscoveryClientConfiguration
implements ApplicationListener {
@Bean
@ConditionalOnMissingBean
protected SimpleAppDiscoveryProperties simpleAppDiscoveryProperties() {
return super.simpleAppDiscoveryProperties();
}
@Bean
@ConditionalOnMissingBean
@Order(Ordered.LOWEST_PRECEDENCE)
protected AppDiscoveryClient simpleDiscoveryClient() {
return super.simpleDiscoveryClient();
}
@Override
public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
setPort(webServerInitializedEvent.getWebServer().getPort());
if (getPort() > 0) {
getSimple().getLocal()
.setAppUri(URI.create(ProtocolScheme.HTTP.scheme() + "://" + Networks.LOCAL_HOSTNAME + ":" + getPort()));
}
}
}