Search in sources :

Example 1 with WebServerInitializedEvent

use of org.springframework.boot.web.context.WebServerInitializedEvent in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
    if (applicationEvent instanceof WebServerInitializedEvent) {
        WebServerInitializedEvent event = (WebServerInitializedEvent) applicationEvent;
        ApplicationContext context = event.getApplicationContext();
        if (context instanceof ConfigurableWebServerApplicationContext) {
            if ("management".equals(((ConfigurableWebServerApplicationContext) context).getServerNamespace())) {
                return;
            }
        }
        this.autoServiceRegistration.setPortIfNeeded(event.getWebServer().getPort());
        this.autoServiceRegistration.start();
    }
}
Also used : ConfigurableWebServerApplicationContext(org.springframework.boot.web.context.ConfigurableWebServerApplicationContext) ConfigurableWebServerApplicationContext(org.springframework.boot.web.context.ConfigurableWebServerApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) WebServerInitializedEvent(org.springframework.boot.web.context.WebServerInitializedEvent)

Aggregations

ConfigurableWebServerApplicationContext (org.springframework.boot.web.context.ConfigurableWebServerApplicationContext)1 WebServerInitializedEvent (org.springframework.boot.web.context.WebServerInitializedEvent)1 ApplicationContext (org.springframework.context.ApplicationContext)1