Search in sources :

Example 1 with ContextRefreshedEvent

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

Example 2 with ContextRefreshedEvent

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

Example 3 with ContextRefreshedEvent

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);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RoutesCollector(org.apache.camel.spring.boot.RoutesCollector) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Example 4 with ContextRefreshedEvent

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

Example 5 with ContextRefreshedEvent

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

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