Search in sources :

Example 16 with ContextRefreshedEvent

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();
        }
    }
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Example 17 with ContextRefreshedEvent

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();
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 18 with ContextRefreshedEvent

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);
}
Also used : ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent)

Example 19 with ContextRefreshedEvent

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Example 20 with ContextRefreshedEvent

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();
        }
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Aggregations

ContextRefreshedEvent (org.springframework.context.event.ContextRefreshedEvent)28 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 ApplicationContext (org.springframework.context.ApplicationContext)6 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)4 Notification (javax.management.Notification)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 Field (java.lang.reflect.Field)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 RoutesCollector (org.apache.camel.spring.boot.RoutesCollector)1 BeansException (org.springframework.beans.BeansException)1