org.springframework.boot.web.context.WebServerInitializedEvent Java Examples

The following examples show how to use org.springframework.boot.web.context.WebServerInitializedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsulAutoServiceRegistrationListener.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example #2
Source File: ApplicationStartListener.java    From Raincat with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onApplicationEvent(final WebServerInitializedEvent event) {
    int port = event.getWebServer().getPort();
    final String host = getHost();
    Address.getInstance()
            .setHost(host)
            .setPort(port)
            .setDomain(String.join(":", host, String.valueOf(port)));
}
 
Example #3
Source File: AbstractAutoServiceRegistration.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Deprecated
public void bind(WebServerInitializedEvent event) {
	ApplicationContext context = event.getApplicationContext();
	if (context instanceof ConfigurableWebServerApplicationContext) {
		if ("management".equals(((ConfigurableWebServerApplicationContext) context)
				.getServerNamespace())) {
			return;
		}
	}
	this.port.compareAndSet(0, event.getWebServer().getPort());
	this.start();
}
 
Example #4
Source File: SimpleDiscoveryClientAutoConfiguration.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
	this.port = webServerInitializedEvent.getWebServer().getPort();
	if (this.port > 0) {
		simple.getLocal()
				.setUri(URI.create("http://"
						+ this.inet.findFirstNonLoopbackHostInfo().getHostname() + ":"
						+ this.port));
	}
}
 
Example #5
Source File: SimpleReactiveDiscoveryClientAutoConfiguration.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
	port = webServerInitializedEvent.getWebServer().getPort();
	if (port > 0) {
		simple.getLocal().setUri(URI.create("http://"
				+ inet.findFirstNonLoopbackHostInfo().getHostname() + ":" + port));
	}
}
 
Example #6
Source File: EurekaAutoServiceRegistration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof WebServerInitializedEvent) {
		onApplicationEvent((WebServerInitializedEvent) event);
	}
	else if (event instanceof ContextClosedEvent) {
		onApplicationEvent((ContextClosedEvent) event);
	}
}
 
Example #7
Source File: EurekaAutoServiceRegistration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public void onApplicationEvent(WebServerInitializedEvent event) {
	// TODO: take SSL into account
	String contextName = event.getApplicationContext().getServerNamespace();
	if (contextName == null || !contextName.equals("management")) {
		int localPort = event.getWebServer().getPort();
		if (this.port.get() == 0) {
			log.info("Updating port to " + localPort);
			this.port.compareAndSet(0, localPort);
			start();
		}
	}
}
 
Example #8
Source File: WebAppAutoConfiguration.java    From saluki with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    int httpPort = event.getWebServer().getPort();
    if (grpcProperties.getRegistryHttpPort() == 0) {
        if (httpPort != 0) {
            grpcProperties.setRegistryHttpPort(httpPort);
        }
    }
}
 
Example #9
Source File: DefaultApplicationFactory.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@EventListener
public void onWebServerInitialized(WebServerInitializedEvent event) {
	String name = event.getApplicationContext().getServerNamespace();
	if ("server".equals(name) || !StringUtils.hasText(name)) {
		localServerPort = event.getWebServer().getPort();
	}
	else if ("management".equals(name)) {
		localManagementPort = event.getWebServer().getPort();
	}
}
 
Example #10
Source File: NacosDiscoveryAutoRegister.java    From nacos-spring-boot-project with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {

    if (!discoveryProperties.isAutoRegister()) {
        return;
    }

    Register register = discoveryProperties.getRegister();

    if (StringUtils.isEmpty(register.getIp())) {
        register.setIp(NetUtils.localIP());
    }

    if (register.getPort() == 0) {
        register.setPort(event.getWebServer().getPort());
    }

    register.getMetadata().put("preserved.register.source", "SPRING_BOOT");

    register.setInstanceId("");

    String serviceName = register.getServiceName();

    if (StringUtils.isEmpty(serviceName)){
        if (StringUtils.isEmpty(applicationName)){
            throw new AutoRegisterException("serviceName notNull");
        }
        serviceName = applicationName;
    }

    try {
        namingService.registerInstance(serviceName, register.getGroupName(),
                register);
        logger.info("Finished auto register service : {}, ip : {}, port : {}",
                serviceName, register.getIp(), register.getPort());
    } catch (NacosException e) {
        throw new AutoRegisterException(e);
    }
}
 
Example #11
Source File: StartEventListener.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Async
@Order
@EventListener(WebServerInitializedEvent.class)
public void afterStart(WebServerInitializedEvent event) {
	Environment environment = event.getApplicationContext().getEnvironment();
	String appName = environment.getProperty("spring.application.name").toUpperCase();
	int localPort = event.getWebServer().getPort();
	String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
	log.info("---[{}]---启动完成,当前使用的端口:[{}],环境变量:[{}]---", appName, localPort, profile);
}
 
Example #12
Source File: GenericEventAdapter.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accepts(Object aEvent)
{
    return aEvent instanceof ApplicationEvent && !(
            aEvent instanceof ApplicationContextEvent || 
            aEvent instanceof ServletRequestHandledEvent ||
            aEvent instanceof SessionCreationEvent ||
            aEvent instanceof SessionDestroyedEvent ||
            aEvent instanceof AbstractAuthorizationEvent ||
            aEvent instanceof AbstractAuthenticationEvent ||
            aEvent instanceof WebServerInitializedEvent);
}
 
Example #13
Source File: ApplicationStartListener.java    From soul with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(final WebServerInitializedEvent event) {
    int port = event.getWebServer().getPort();
    final String host = getHost();
    final String domain = System.getProperty("soul.httpPath");
    if (StringUtils.isBlank(domain)) {
        SoulDomain.getInstance()
                .setHttpPath("http://" + String.join(":", host, String.valueOf(port)));
    } else {
        SoulDomain.getInstance()
                .setHttpPath(domain);
    }
}
 
Example #14
Source File: SpringBootWebTwoConnectorsApplicationTests.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    Service service = ((TomcatWebServer) event.getWebServer()).getTomcat().getService();
    for (Connector connector : service.findConnectors()) {
        if (connector.getSecure()) {
            this.httpsPort = connector.getLocalPort();
        } else {
            this.httpPort = connector.getLocalPort();
        }
    }
}
 
Example #15
Source File: StandaloneShutdownDialog.java    From webanno with Apache License 2.0 4 votes vote down vote up
@EventListener
public void onApplicationEvent(WebServerInitializedEvent aEvt) {
    port = aEvt.getWebServer().getPort();
}
 
Example #16
Source File: ConsulAutoServiceRegistrationListener.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return WebServerInitializedEvent.class.isAssignableFrom(eventType);
}
 
Example #17
Source File: EurekaAutoServiceRegistration.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return WebServerInitializedEvent.class.isAssignableFrom(eventType)
			|| ContextClosedEvent.class.isAssignableFrom(eventType);
}
 
Example #18
Source File: ConsulAutoServiceRegistration.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
@Override
public void bind(WebServerInitializedEvent event) {
	// do nothing so we can listen for this event in a different class
	// this ensures start() can be retried if spring-retry is available
}
 
Example #19
Source File: AbstractAutoServiceRegistration.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void onApplicationEvent(WebServerInitializedEvent event) {
	bind(event);
}
 
Example #20
Source File: DependencyConfig.java    From spring-cloud-zookeeper with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
	this.port = event.getWebServer().getPort();
}
 
Example #21
Source File: SeleniumContainerTest.java    From testcontainers-java with MIT License 4 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.addApplicationListener((ApplicationListener<WebServerInitializedEvent>) event -> {
        Testcontainers.exposeHostPorts(event.getWebServer().getPort());
    });
}
 
Example #22
Source File: SpringBootDemoAllApplication.java    From spring-boot-demo-all with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    // TODO Auto-generated method stub
    this.event = event;
}
 
Example #23
Source File: TelemetryServiceImpl.java    From webanno with Apache License 2.0 4 votes vote down vote up
@EventListener
public void onApplicationEvent(WebServerInitializedEvent aEvt)
{
    port = aEvt.getWebServer().getPort();
}
 
Example #24
Source File: ServerStartedInitializingBean.java    From karate with MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent e) {
	localPort = e.getWebServer().getPort();
	logger.info("after runtime init, local server port: {}", localPort);
}
 
Example #25
Source File: ServiceInfoListener.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    this.serverPort = event.getWebServer().getPort();
}
 
Example #26
Source File: WebConfiguration.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
@EventListener(WebServerInitializedEvent.class)
public void onWebServerReady(WebServerInitializedEvent event) {
    System.out.println("当前 WebServer 实现类为:" + event.getWebServer().getClass().getName());
}
 
Example #27
Source File: ServerConfig.java    From Moss with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    serverPort = event.getWebServer().getPort();
}