Java Code Examples for org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent

The following examples show how to use org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent. These examples are extracted from open source projects. 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 Project: Moss   Source File: DiscoveryClientRegistrationInvoker.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void customize(ConfigurableApplicationContext context) {
    if (context instanceof EmbeddedWebApplicationContext
            && !AdminEndpointApplicationRunListener.isEmbeddedServletServer(context.getEnvironment())) {
        MetaDataProvider metaDataProvider = context.getBean(MetaDataProvider.class);
        EmbeddedServletContainer embeddedServletContainer = new EmbeddedServletContainer() {

            @Override
            public void start() throws EmbeddedServletContainerException {

            }

            @Override
            public void stop() throws EmbeddedServletContainerException {

            }

            @Override
            public int getPort() {
                return metaDataProvider.getServerPort();
            }
        };
        context.publishEvent(new EmbeddedServletContainerInitializedEvent((EmbeddedWebApplicationContext) context, embeddedServletContainer));
    }
}
 
Example 2
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    int port = event.getSource().getPort();
    String serverAddress = ngrokProperties.getServerAddress();
    int serverPort = ngrokProperties.getServerPort();
    String subdomain = ngrokProperties.getSubdomain();
    String hostname = ngrokProperties.getHostname();
    String proto = ngrokProperties.getProto();
    int remotePort = ngrokProperties.getRemotePort();
    String httpAuth = ngrokProperties.getHttpAuth();

    Tunnel tunnel = new Tunnel.TunnelBuild()
            .setPort(port)
            .setProto(proto)
            .setSubDomain(subdomain)
            .setHostname(hostname)
            .setRemotePort(remotePort)
            .setHttpAuth(httpAuth)
            .build();
    new NgrokClient(serverAddress, serverPort)
            .addTunnel(tunnel).start();
}
 
Example 3
Source Project: Lottor   Source File: ApplicationStartListener.java    License: MIT License 5 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    int port = event.getEmbeddedServletContainer().getPort();
    final String host = getHost();
    Address.getInstance()
            .setHost(host)
            .setPort(port)
            .setDomain(String.join(":", host, String.valueOf(port)));

}
 
Example 4
Source Project: pig   Source File: RouteConfigInitListener.java    License: MIT License 5 votes vote down vote up
/**
 * Callback used to run the bean.
 * 初始化路由配置的数据,避免gateway 依赖业务模块
 *
 */
@EventListener(value = {EmbeddedServletContainerInitializedEvent.class})
public void init() {
    log.info("开始初始化路由配置数据");
    EntityWrapper wrapper = new EntityWrapper();
    wrapper.eq(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
    List<SysZuulRoute> routeList = sysZuulRouteService.selectList(wrapper);
    if (CollUtil.isNotEmpty(routeList)) {
        redisTemplate.opsForValue().set(CommonConstant.ROUTE_KEY, routeList);
        log.info("更新Redis中路由配置数据:{}条", routeList.size());
    }
    log.info("初始化路由配置数据完毕");
}
 
Example 5
Source Project: pig   Source File: GroovyLoadInitListener.java    License: MIT License 5 votes vote down vote up
@EventListener(value = {EmbeddedServletContainerInitializedEvent.class})
public void init() {
    MonitoringHelper.initMocks();
    FilterLoader.getInstance().setCompiler(new GroovyCompiler());
    FilterFileManager.setFilenameFilter(new GroovyFileFilter());
    try {
        FilterFileManager.init(10, groovyPath);
    } catch (Exception e) {
        log.error("初始化网关Groovy 文件失败 {}", e);
    }
    log.warn("初始化网关Groovy 文件成功");
}
 
Example 6
Source Project: mojito   Source File: WSTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationListener<EmbeddedServletContainerInitializedEvent> getApplicationListenerEmbeddedServletContainerInitializedEvent() {
    return new ApplicationListener<EmbeddedServletContainerInitializedEvent>() {

        @Override
        public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
            int serverPort = event.getEmbeddedServletContainer().getPort();
            logger.debug("Saving port number = {}", serverPort);
            resttemplateConfig.setPort(serverPort);
        }
    };
}
 
Example 7
Source Project: mojito   Source File: CLITestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationListener<EmbeddedServletContainerInitializedEvent> getApplicationListenerEmbeddedServletContainerInitializedEvent() {

    return new ApplicationListener<EmbeddedServletContainerInitializedEvent>() {

        @Override
        public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
            int serverPort = event.getEmbeddedServletContainer().getPort();
            logger.debug("Saving port number = {}", serverPort);
            resttemplateConfig.setPort(serverPort);
        }
    };
}
 
Example 8
Source Project: tx-lcn   Source File: ApplicationStartListener.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    int serverPort = event.getEmbeddedServletContainer().getPort();
    String ip = getIp();
    Constants.address = ip+":"+serverPort;
}
 
Example 9
Source Project: tx-lcn   Source File: ServerListener.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    this.serverPort = event.getEmbeddedServletContainer().getPort();
}
 
Example 10
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
	port = event.getEmbeddedServletContainer().getPort();
	client = new CrnkClient("http://localhost:" + port + "/api");
	client.addModule(new ClientTestModule());
}
 
Example 11
Source Project: elephant   Source File: BeanAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
	this.registerCenter4Provider.registerServer(buildServerDto());
}
 
Example 12
Source Project: karate   Source File: ServerStartedInitializingBean.java    License: MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent e) {
	localPort = e.getEmbeddedServletContainer().getPort();
	logger.info("after runtime init, local server port: {}", localPort);
}
 
Example 13
Source Project: kubernetes-zipkin   Source File: HelloController.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    this.port = event.getEmbeddedServletContainer().getPort();
}
 
Example 14
Source Project: example-restful-project   Source File: PortHolder.java    License: MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(
        EmbeddedServletContainerInitializedEvent event) {
    port = event.getEmbeddedServletContainer().getPort();
}
 
Example 15
Source Project: logstash   Source File: FrameworkConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    httpPort = event.getEmbeddedServletContainer().getPort();
}