use of org.springframework.context.event.ContextRefreshedEvent in project tomee by apache.
the class SpringBus method onApplicationEvent.
public void onApplicationEvent(ApplicationEvent event) {
if (ctx == null) {
return;
}
boolean doIt = false;
ApplicationContext ac = ctx;
while (ac != null) {
if (event.getSource() == ac) {
doIt = true;
break;
}
ac = ac.getParent();
}
if (doIt) {
if (event instanceof ContextRefreshedEvent) {
if (getState() != BusState.RUNNING) {
initialize();
}
} else if (event instanceof ContextClosedEvent && getState() == BusState.RUNNING) {
// The bus could be create by using SpringBusFactory.createBus("/cxf.xml");
// Just to make sure the shutdown is called rightly
shutdown();
}
}
}
use of org.springframework.context.event.ContextRefreshedEvent in project spring-framework by spring-projects.
the class BeanFactoryPostProcessorTests method testBeanFactoryPostProcessorWithInnerBeanAsApplicationListener.
@Test
public void testBeanFactoryPostProcessorWithInnerBeanAsApplicationListener() {
StaticApplicationContext ac = new StaticApplicationContext();
RootBeanDefinition rbd = new RootBeanDefinition(NestingBeanFactoryPostProcessor.class);
rbd.getPropertyValues().add("listeningBean", new RootBeanDefinition(ListeningBean.class));
ac.registerBeanDefinition("bfpp", rbd);
ac.refresh();
boolean condition = ac.getBean(NestingBeanFactoryPostProcessor.class).getListeningBean().received instanceof ContextRefreshedEvent;
assertThat(condition).isTrue();
}
use of org.springframework.context.event.ContextRefreshedEvent in project spring-framework by spring-projects.
the class AbstractApplicationContext method finishRefresh.
/**
* Finish the refresh of this context, invoking the LifecycleProcessor's
* onRefresh() method and publishing the
* {@link org.springframework.context.event.ContextRefreshedEvent}.
*/
protected void finishRefresh() {
// Clear context-level resource caches (such as ASM metadata from scanning).
clearResourceCaches();
// Initialize lifecycle processor for this context.
initLifecycleProcessor();
// Propagate refresh to lifecycle processor first.
getLifecycleProcessor().onRefresh();
// Publish the final event.
publishEvent(new ContextRefreshedEvent(this));
// Participate in LiveBeansView MBean, if active.
LiveBeansView.registerApplicationContext(this);
}
use of org.springframework.context.event.ContextRefreshedEvent in project spring-boot by spring-projects.
the class AutoConfigurationReportLoggingInitializerTests method logsDebugOnContextRefresh.
@Test
public void logsDebugOnContextRefresh() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
this.initializer.initialize(context);
context.register(Config.class);
context.refresh();
this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
assertThat(this.debugLog.size()).isNotEqualTo(0);
}
use of org.springframework.context.event.ContextRefreshedEvent in project cxf by apache.
the class SpringBus method onApplicationEvent.
public void onApplicationEvent(ApplicationEvent event) {
if (ctx == null) {
return;
}
boolean doIt = false;
ApplicationContext ac = ctx;
while (ac != null && !doIt) {
if (event.getSource() == ac) {
doIt = true;
break;
}
ac = ac.getParent();
}
if (doIt) {
if (event instanceof ContextRefreshedEvent) {
if (getState() != BusState.RUNNING) {
initialize();
}
} else if (event instanceof ContextClosedEvent && getState() == BusState.RUNNING) {
// The bus could be create by using SpringBusFactory.createBus("/cxf.xml");
// Just to make sure the shutdown is called rightly
shutdown();
}
}
}
Aggregations