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

The following examples show how to use org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent. 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: DiscoveryClientRegistrationInvoker.java    From Moss with 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
Source File: NgrokEmbeddedServletContainerInitializedEventListener.java    From fast-ngrok with Apache License 2.0 6 votes vote down vote up
@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 File: ApplicationStartListener.java    From Lottor with 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 File: RouteConfigInitListener.java    From pig with 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 File: GroovyLoadInitListener.java    From pig with 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 File: WSTestBase.java    From mojito with 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 File: CLITestBase.java    From mojito with 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 File: ApplicationStartListener.java    From tx-lcn with 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 File: ServerListener.java    From tx-lcn with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    this.serverPort = event.getEmbeddedServletContainer().getPort();
}
 
Example #10
Source File: ReactiveServletTestApplication.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
	port = event.getEmbeddedServletContainer().getPort();
	client = new CrnkClient("http://localhost:" + port + "/api");
	client.addModule(new ClientTestModule());
}
 
Example #11
Source File: BeanAutoConfiguration.java    From elephant with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
	this.registerCenter4Provider.registerServer(buildServerDto());
}
 
Example #12
Source File: ServerStartedInitializingBean.java    From karate with 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 File: HelloController.java    From kubernetes-zipkin with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    this.port = event.getEmbeddedServletContainer().getPort();
}
 
Example #14
Source File: PortHolder.java    From example-restful-project with MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(
        EmbeddedServletContainerInitializedEvent event) {
    port = event.getEmbeddedServletContainer().getPort();
}
 
Example #15
Source File: FrameworkConfig.java    From logstash with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
    httpPort = event.getEmbeddedServletContainer().getPort();
}