类org.springframework.context.event.ContextStartedEvent源码实例Demo

下面列出了怎么用org.springframework.context.event.ContextStartedEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Almost-Famous   文件: ApplicationEventListener.java
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        LOGGER.debug("初始化环境变量");
    } else if (event instanceof ApplicationPreparedEvent) {
        LOGGER.debug("初始化完成");
    } else if (event instanceof ContextRefreshedEvent) {
        LOGGER.debug("应用刷新");
    } else if (event instanceof ApplicationReadyEvent) {
        LOGGER.debug("应用已启动完成");
    } else if (event instanceof ContextStartedEvent) {
        LOGGER.debug("应用启动,需要在代码动态添加监听器才可捕获");
    } else if (event instanceof ContextStoppedEvent) {
        LOGGER.debug("应用停止");
    } else if (event instanceof ContextClosedEvent) {
        ApplicationContext applicationContext = ((ContextClosedEvent) event).getApplicationContext();
        grpcClient = applicationContext.getBean(GrpcClient.class);
        grpcClient.close();
        LOGGER.debug("应用关闭");
    }

}
 
源代码2 项目: Almost-Famous   文件: ApplicationEventListener.java
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        LOG.debug("初始化环境变量");
    } else if (event instanceof ApplicationPreparedEvent) {
        LOG.debug("初始化完成");
        LOG.debug("初始GameData策划数据");
        ConfigManager.loadGameData(this.configPath);
    } else if (event instanceof ContextRefreshedEvent) {
        LOG.debug("应用刷新");
    } else if (event instanceof ApplicationReadyEvent) {
        LOG.debug("应用已启动完成");
    } else if (event instanceof ContextStartedEvent) {
        LOG.debug("应用启动,需要在代码动态添加监听器才可捕获");
    } else if (event instanceof ContextStoppedEvent) {
        LOG.debug("应用停止");
    } else if (event instanceof ContextClosedEvent) {
        ApplicationContext context = ((ContextClosedEvent) event).getApplicationContext();
        rpcClient = context.getBean(RpcClient.class);
        rpcClient.close();
        LOG.error("应用关闭");
    } else {

    }
}
 
源代码3 项目: Almost-Famous   文件: ApplicationEventListener.java
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        LOG.debug("初始化环境变量");
    } else if (event instanceof ApplicationPreparedEvent) {
        LOG.debug("初始化完成");
        LOG.debug("初始GameData策划数据");
        String path = ApplicationEventListener.class.getResource("/gamedata").getFile();
        ConfigManager.loadGameData(path);
    } else if (event instanceof ContextRefreshedEvent) {
        LOG.debug("应用刷新");
    } else if (event instanceof ApplicationReadyEvent) {
        LOG.debug("应用已启动完成");
    } else if (event instanceof ContextStartedEvent) {
        LOG.debug("应用启动,需要在代码动态添加监听器才可捕获");
    } else if (event instanceof ContextStoppedEvent) {
        LOG.debug("应用停止");
    } else if (event instanceof ContextClosedEvent) {
        ApplicationContext applicationContext = ((ContextClosedEvent) event).getApplicationContext();
        grpcClient = applicationContext.getBean(GrpcClient.class);
        grpcClient.close();
        LOG.debug("应用关闭");
    }
}
 
/**
 * Do annotation on class type resolve action after spring container started.
 * 
 * @param event spring application event
 */
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextStartedEvent || event instanceof ContextRefreshedEvent) {

        // only execute this method once. bug fix for ContextRefreshedEvent will invoke twice on spring MVC servlet
        if (started.compareAndSet(false, true)) {
            for (BeanInfo bean : typeAnnotationedBeans) {
                if (getCallback() != null) {
                    Object targetBean = beanFactory.getBean(bean.name);
                    getCallback().annotationAtTypeAfterStarted(bean.annotation, targetBean, bean.name, beanFactory);
                }
            }
        } else {
            LOGGER.warn("onApplicationEvent of application event [" + event
                    + "] ignored due to processor already started.");
        }

    }

}
 
/**
 * 应用程序启动过程监听
 * 
 * @time 2018年4月10日 下午5:05:33
 * @version V1.0
 * @param event
 */
@Override
public void onApplicationEvent(ApplicationEvent event) {
	// 在这里可以监听到Spring Boot的生命周期
	if (event instanceof ApplicationEnvironmentPreparedEvent) { // 初始化环境变量
		log.debug("初始化环境变量");
	} else if (event instanceof ApplicationPreparedEvent) { // 初始化完成
		log.debug("初始化环境变量完成");
	} else if (event instanceof ContextRefreshedEvent) { // 应用刷新,当ApplicationContext初始化或者刷新时触发该事件。
		log.debug("应用刷新");
	} else if (event instanceof ApplicationReadyEvent) {// 应用已启动完成
		log.debug("应用已启动完成");
	} else if (event instanceof ContextStartedEvent) { // 应用启动,Spring2.5新增的事件,当容器调用ConfigurableApplicationContext的
														// Start()方法开始/重新开始容器时触发该事件。
		log.debug("应用启动");
	} else if (event instanceof ContextStoppedEvent) { // 应用停止,Spring2.5新增的事件,当容器调用ConfigurableApplicationContext
														// 的Stop()方法停止容器时触发该事件。
		log.debug("应用停止");
	} else if (event instanceof ContextClosedEvent) { // 应用关闭,当ApplicationContext被关闭时触发该事件。容器被关闭时,其管理的所有
														// 单例Bean都被销毁。
		log.debug("应用关闭");
	} else {
	}
}
 
源代码6 项目: vividus   文件: ContextStartedEventListener.java
@Override
public void onApplicationEvent(ContextStartedEvent event)
{
    ApplicationContext applicationContext = event.getApplicationContext();

    AllureLogAppender allureLogAppender = AllureLogAppender.getInstance();
    allureLogAppender.setAllureStoryReporter(applicationContext.getBean(AllureStoryReporter.class));
}
 
源代码7 项目: vividus   文件: StartContextListenerTests.java
@Test
void shouldDeleteCleanableDirectories(@TempDir Path tempDir) throws IOException
{
    Path dir = tempDir.resolve("to-be-cleaned-up");
    Files.createDirectories(dir);
    StartContextListener startContextListener = new StartContextListener();
    startContextListener.setCleanableDirectories(Optional.of(List.of(dir.toFile())));
    startContextListener.onApplicationEvent(mock(ContextStartedEvent.class));
    assertTrue(Files.exists(tempDir));
    assertFalse(Files.exists(dir));
}
 
源代码8 项目: vividus   文件: StartContextListenerTests.java
@Test
void shouldIgnoreNonExistentCleanableDirectories(@TempDir Path tempDir)
{
    StartContextListener startContextListener = new StartContextListener();
    startContextListener.setCleanableDirectories(Optional.of(List.of(tempDir.resolve("non-existent").toFile())));
    startContextListener.onApplicationEvent(mock(ContextStartedEvent.class));
    assertTrue(Files.exists(tempDir));
}
 
源代码9 项目: document-management-software   文件: Context.java
/**
 * Processes a newly incoming event on appropriated events that registered
 * itself on it
 * 
 * @param event the event to process
 */
@Override
public synchronized void onApplicationEvent(ApplicationEvent event) {
	if ((event instanceof ContextStartedEvent) || (event instanceof ContextRefreshedEvent)) {
		processEvents(SystemEventStatus.BEANS_AVAILABLE);
	} else if (event instanceof ContextClosedEvent) {
		processEvents(SystemEventStatus.SYSTEM_DESTORY);
	}

}
 
源代码10 项目: micronaut-spring   文件: ContextEventAdapter.java
@Override
public void onApplicationEvent(Object event) {
    if (event instanceof StartupEvent) {
        eventPublisher.publishEvent(new ContextStartedEvent(
            applicationContext
        ));
    } else if (event instanceof ShutdownEvent) {
        eventPublisher.publishEvent(new ContextClosedEvent(
                applicationContext
        ));
    }
}
 
源代码11 项目: realtime-analytics   文件: MetricServer.java
@Override
public void onApplicationEvent(ApplicationEvent event) {

    if (event instanceof ContextStartedEvent) {
        this.startStandAlone();
    } else if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent) {
        this.stopStandAlone();
    }
}
 
源代码12 项目: vividus   文件: StartContextListener.java
@Override
public void onApplicationEvent(ContextStartedEvent event)
{
    cleanableDirectories.stream().flatMap(List::stream).forEach(this::deleteDirectory);
}
 
@Override
public void start() {
	getLifecycleProcessor().start();
	publishEvent(new ContextStartedEvent(this));
}
 
@Override
public void onApplicationEvent(ContextStartedEvent event) {
	System.err.println("============Start 执行=========== ");
}
 
源代码15 项目: geekbang-lessons   文件: ApplicationListenerDemo.java
@EventListener
public void onApplicationEvent(ContextStartedEvent event) {
    println("@EventListener - 接收到 Spring ContextStartedEvent");
}
 
@Override
public void start() {
	getLifecycleProcessor().start();
	publishEvent(new ContextStartedEvent(this));
}
 
源代码17 项目: micronaut-spring   文件: MyNamedService.java
@EventListener
public void onStartup(ContextStartedEvent startedEvent) {
    this.lastEvent = startedEvent;
}
 
源代码18 项目: micronaut-spring   文件: MyNamedService.java
public ContextStartedEvent getLastEvent() {
    return lastEvent;
}
 
源代码19 项目: lams   文件: AbstractApplicationContext.java
@Override
public void start() {
	getLifecycleProcessor().start();
	publishEvent(new ContextStartedEvent(this));
}
 
@Override
public void start() {
	getLifecycleProcessor().start();
	publishEvent(new ContextStartedEvent(this));
}
 
源代码21 项目: aliada-tool   文件: PipelineStartupListener.java
@Override
public void onApplicationEvent(final ContextStartedEvent event) {
	LOGGER.info(MessageCatalog._00022_PIPELINE_STARTING);
	
	LOGGER.info(MessageCatalog._00023_PIPELINE_STARTED);
}
 
源代码22 项目: tutorials   文件: ContextEventListener.java
@Order(2)
@EventListener
public void handleContextRefreshEvent(ContextStartedEvent ctxStartEvt) {
    System.out.println("Context Start Event received.");
}
 
源代码23 项目: tutorials   文件: ContextEventListener.java
@Order(1)
@EventListener(classes = { ContextStartedEvent.class, ContextStoppedEvent.class })
public void handleMultipleEvents() {
    System.out.println("Multi-event listener invoked");
}
 
源代码24 项目: tutorials   文件: AnnotationDrivenEventListener.java
@EventListener
public void handleContextStart(final ContextStartedEvent cse) {
    System.out.println("Handling context started event.");
    hitContextStartedHandler = true;
}
 
 同包方法