use of org.springframework.context.event.ContextRefreshedEvent in project java-chassis by ServiceComb.
the class CseApplicationListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();
//TODO to load when webapplication context is used for discovery client, need to check if can use the order and undo this change with proper fix.
if (!isInit) {
try {
BeanUtils.setContext(applicationContext);
bootListenerList = applicationContext.getBeansOfType(BootListener.class).values();
triggerEvent(EventType.BEFORE_HANDLER);
HandlerConfigUtils.init();
triggerEvent(EventType.AFTER_HANDLER);
triggerEvent(EventType.BEFORE_PRODUCER_PROVIDER);
producerProviderManager.init();
triggerEvent(EventType.AFTER_PRODUCER_PROVIDER);
triggerEvent(EventType.BEFORE_CONSUMER_PROVIDER);
consumerProviderManager.init();
triggerEvent(EventType.AFTER_CONSUMER_PROVIDER);
triggerEvent(EventType.BEFORE_TRANSPORT);
transportManager.init();
triggerEvent(EventType.AFTER_TRANSPORT);
schemaListenerManager.notifySchemaListener();
triggerEvent(EventType.BEFORE_REGISTRY);
RegistryUtils.init();
triggerEvent(EventType.AFTER_REGISTRY);
// TODO 服务优雅退出
if (applicationContext instanceof AbstractApplicationContext) {
((AbstractApplicationContext) applicationContext).registerShutdownHook();
}
isInit = true;
} catch (Exception e) {
LOGGER.error("cse init failed, {}", FortifyUtils.getErrorInfo(e));
}
}
} else if (event instanceof ContextClosedEvent) {
LOGGER.warn("cse is closing now...");
RegistryUtils.destory();
isInit = false;
}
}
use of org.springframework.context.event.ContextRefreshedEvent in project spring-boot by spring-projects.
the class AutoConfigurationReportLoggingInitializerTests method logsOutput.
@Test
public void logsOutput() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
this.initializer.initialize(context);
context.register(Config.class);
ConditionEvaluationReport.get(context.getBeanFactory()).recordExclusions(Arrays.asList("com.foo.Bar"));
context.refresh();
this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
for (String message : this.debugLog) {
System.out.println(message);
}
// Just basic sanity check, test is for visual inspection
String l = this.debugLog.get(0);
assertThat(l).contains("not a servlet web application (OnWebApplicationCondition)");
}
use of org.springframework.context.event.ContextRefreshedEvent in project camel by apache.
the class Configuration method shouldOnlyCollectRoutesOnce.
@Test
public void shouldOnlyCollectRoutesOnce() {
GenericApplicationContext parent = new GenericApplicationContext();
parent.refresh();
ConfigurableApplicationContext context = new SpringApplicationBuilder(Configuration.class).web(false).parent(parent).run();
ContextRefreshedEvent refreshEvent = new ContextRefreshedEvent(context);
RoutesCollector collector = context.getBean(RoutesCollector.class);
//no changes should happen here
collector.onApplicationEvent(refreshEvent);
}
use of org.springframework.context.event.ContextRefreshedEvent in project nikita-noark5-core by HiOA-ABI.
the class NikitaApplicationListenerBean method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();
applicationContext.getBean(AfterApplicationStartup.class).afterApplicationStarts();
}
}
use of org.springframework.context.event.ContextRefreshedEvent in project pigatron-web by pigatron-industries.
the class AbstractAdminCoreIntegrationTest method dbSetup.
protected void dbSetup() {
mongoTemplate.getDb().dropDatabase();
// force initial data setup
publisher.publishEvent(new ContextRefreshedEvent(context));
}
Aggregations