org.springframework.context.event.ApplicationContextEvent.getApplicationContext()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中org.springframework.context.event.ApplicationContextEvent.getApplicationContext()方法的一些代码示例,展示了ApplicationContextEvent.getApplicationContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContextEvent.getApplicationContext()方法的具体详情如下:
包路径:org.springframework.context.event.ApplicationContextEvent
类名称:ApplicationContextEvent
方法名:getApplicationContext

ApplicationContextEvent.getApplicationContext介绍

[英]Get the ApplicationContext that the event was raised for.
[中]获取引发事件的应用程序上下文。

代码示例

代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba

@Override
public void onApplicationEvent(T event) {
  if (event instanceof ApplicationContextEvent) {
    ApplicationContext applicationContext = ((ApplicationContextEvent) event)
        .getApplicationContext();
    // skip bootstrap context or super parent context.
    if (applicationContext.getParent() == null
        || BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext
            .getEnvironment().getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
      return;
    }
  }
  Class<?> clazz = getClass();
  lockMap.putIfAbsent(clazz, new AtomicBoolean(false));
  AtomicBoolean handled = lockMap.get(clazz);
  // only execute once.
  if (!handled.compareAndSet(false, true)) {
    return;
  }
  if (conditionalOnClass() != null) {
    try {
      Class.forName(conditionalOnClass());
    }
    catch (ClassNotFoundException e) {
      // ignored
      return;
    }
  }
  handleEvent(event);
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public synchronized void onApplicationEvent(ApplicationContextEvent event) {
  ApplicationContext context = event.getApplicationContext();
  if (event instanceof ContextRefreshedEvent) {
    boolean contextHasIdGenerator = context.getBeanNamesForType(IdGenerator.class).length > 0;
    if (contextHasIdGenerator) {
      if (this.setIdGenerator(context)) {
        IdGeneratorConfigurer.generatorContextId.add(context.getId());
      }
    }
  }
  else if (event instanceof ContextClosedEvent) {
    if (IdGeneratorConfigurer.generatorContextId.contains(context.getId())) {
      if (IdGeneratorConfigurer.generatorContextId.size() == 1) {
        this.unsetIdGenerator();
      }
      IdGeneratorConfigurer.generatorContextId.remove(context.getId());
    }
  }
}

代码示例来源:origin: com.github.skjolber.mockito-rest-spring/core

public void onApplicationEvent(ApplicationContextEvent event) {
  if(event instanceof ContextRefreshedEvent) {
    // spring context has been started
    ApplicationContext applicationContext = event.getApplicationContext();
    for(Class<?> bean : mockTargetBeans) {
      Object value = applicationContext.getBean(bean);
      map.put(bean, value);
    }
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

private void onApplicationContextEvent(ApplicationContextEvent e) {
  if (e instanceof ContextStartedEvent) {
    onContextStarted(e.getApplicationContext());
  } else if (e instanceof ContextStoppedEvent) {
    onContextStopped(e.getApplicationContext());
  }
}

代码示例来源:origin: spheras/messic

@Override
public void onApplicationEvent( ApplicationContextEvent event )
{
  ApplicationContext ac = event.getApplicationContext();
  synchronized ( this )
  {
    if ( ac != null && !this.flagMessicInited )
    {
      this.flagMessicInited = true;
      checkService();
    }
  }
}

代码示例来源:origin: spheras/messic

@Override
public void onApplicationEvent( ApplicationContextEvent arg0 )
{
  ApplicationContext ac = arg0.getApplicationContext();
  synchronized ( this )
  {
    if ( ac != null && !this.flagMessicInited )
    {
      this.flagMessicInited = true;
      refreshServer();
    }
  }
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

@Override
public void onApplicationEvent(ApplicationContextEvent event) {
  Assert.notNull(event, "event must not be null");
  ApplicationContext applicationContext = event.getApplicationContext();
  //remove context from created registry
  applicationContextsRegistry.remove(applicationContext);
  //add new found contexts
  if (event instanceof ContextRefreshedEvent || event instanceof ContextStartedEvent) {
    LOG.info("Create new registry for context '{}.'", applicationContext.getDisplayName());
    applicationContextsRegistry.put(applicationContext, new ApplicationContextRegistry(applicationContext));
  }
}

代码示例来源:origin: shunyang/thrift-all

@Override
public void onApplicationEvent(ApplicationContextEvent event) {
  ApplicationContext context = event.getApplicationContext();
  if (event instanceof ContextRefreshedEvent|| event instanceof ContextStartedEvent){
    initThriftServer(context);
    logger.debug("Thrift Server 配置加载成功");
  }
  if (event instanceof ContextStoppedEvent || event instanceof ContextClosedEvent){
    try {
      proxyBeanLocal.destroy();
    } catch (Exception e) {
      logger.error("Thrift Server 关闭失败");
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: wanghongfei/gae

@Override
public void onApplicationEvent(ApplicationContextEvent event) {
  // 上下文初始化完成时启动vertx
  if (event instanceof ContextRefreshedEvent) {
    startHttpServer(event.getApplicationContext());
  } else if (event instanceof ContextClosedEvent) {
    // 上下文关闭时关闭vertx
    IndexIncrementLoader loader = event.getApplicationContext().getBean(IndexIncrementLoader.class);
    try {
      vertx.close();
      if (null != loader) {
        loader.shutdown();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: org.eclipse.gemini.blueprint/gemini-blueprint-core

public void onApplicationEvent(ApplicationContextEvent event) {
  // publish
  if (event instanceof ContextRefreshedEvent) {
    registerService(event.getApplicationContext());
  } else if (event instanceof ContextClosedEvent) {
    unregisterService();
  }
}

代码示例来源:origin: com.dell.cpsd.common.messaging/common-rabbitmq

@Override
public void onApplicationEvent(ApplicationContextEvent event)
{
  if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent || event instanceof ContextRefreshedEvent)
  {
    ApplicationContext context = event.getApplicationContext();
    RegistrationNotifierService registrationNotifierService = context.getBean(RegistrationNotifierService.class);
    if (registrationNotifierService == null)
    {
      return;
    }
    if (event instanceof ContextRefreshedEvent)
    {
      Map<String, MessageRegistrationAware> msgRegistrations = context.getBeansOfType(MessageRegistrationAware.class);
      Map<String, Binding> bindings = context.getBeansOfType(Binding.class);
      for (Map.Entry<String, MessageRegistrationAware> registration : msgRegistrations.entrySet())
      {
        MessageRegistrationAware messageRegistration = registration.getValue();
        if (messageRegistration.isAutoRegister())
        {
          notify(registrationNotifierService, registration.getValue(), bindings.values());
        }
      }
    }
    else
    {
      withdraw(registrationNotifierService);
    }
  }
}

代码示例来源:origin: com.dell.cpsd/common-rabbitmq

@Override
public void onApplicationEvent(ApplicationContextEvent event)
{
  if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent || event instanceof ContextRefreshedEvent)
  {
    ApplicationContext context = event.getApplicationContext();
    RegistrationNotifierService registrationNotifierService = context.getBean(RegistrationNotifierService.class);
    if (registrationNotifierService == null)
    {
      return;
    }
    if (event instanceof ContextRefreshedEvent)
    {
      Map<String, MessageRegistrationAware> msgRegistrations = context.getBeansOfType(MessageRegistrationAware.class);
      Map<String, Binding> bindings = context.getBeansOfType(Binding.class);
      for (Map.Entry<String, MessageRegistrationAware> registration : msgRegistrations.entrySet())
      {
        MessageRegistrationAware messageRegistration = registration.getValue();
        if (messageRegistration.isAutoRegister())
        {
          notify(registrationNotifierService, registration.getValue(), bindings.values());
        }
      }
    }
    else
    {
      withdraw(registrationNotifierService);
    }
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-alicloud-context

@Override
public void onApplicationEvent(T event) {
  if (event instanceof ApplicationContextEvent) {
    ApplicationContext applicationContext = ((ApplicationContextEvent) event)
        .getApplicationContext();
    // skip bootstrap context or super parent context.
    if (applicationContext.getParent() == null
        || BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext
            .getEnvironment().getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
      return;
    }
  }
  Class<?> clazz = getClass();
  lockMap.putIfAbsent(clazz, new AtomicBoolean(false));
  AtomicBoolean handled = lockMap.get(clazz);
  // only execute once.
  if (!handled.compareAndSet(false, true)) {
    return;
  }
  if (conditionalOnClass() != null) {
    try {
      Class.forName(conditionalOnClass());
    }
    catch (ClassNotFoundException e) {
      // ignored
      return;
    }
  }
  handleEvent(event);
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

@Override
public synchronized void onApplicationEvent(ApplicationContextEvent event) {
  ApplicationContext context = event.getApplicationContext();
  if (event instanceof ContextRefreshedEvent) {
    boolean contextHasIdGenerator = context.getBeanNamesForType(IdGenerator.class).length > 0;
    if (contextHasIdGenerator) {
      if (this.setIdGenerator(context)) {
        IdGeneratorConfigurer.generatorContextId.add(context.getId());
      }
    }
  }
  else if (event instanceof ContextClosedEvent) {
    if (IdGeneratorConfigurer.generatorContextId.contains(context.getId())) {
      if (IdGeneratorConfigurer.generatorContextId.size() == 1) {
        this.unsetIdGenerator();
      }
      IdGeneratorConfigurer.generatorContextId.remove(context.getId());
    }
  }
}

代码示例来源:origin: com.airlenet/play-integration-core

@Override
public void onApplicationEvent(ApplicationContextEvent event) {
  if (event instanceof ContextStartedEvent) {
    ApplicationContext applicationContext = event.getApplicationContext();
    if (applicationContext.getParent() == null) {// root 开始
      System.out.println("Play Framework Starting...");
    }
  }
  if (event instanceof ContextRefreshedEvent) {
    ApplicationContext applicationContext = event.getApplicationContext();
    if(lifeCycleListeners != null) {
      AnnotationAwareOrderComparator.sort(lifeCycleListeners);
    }
    if (applicationContext.getParent() == null) {// root 启动完成
      if (lifeCycleListeners != null) {
        lifeCycleListeners.forEach(listener -> listener.onRootContextRefreshed());
      }
    } else {
      if (lifeCycleListeners != null) {
        lifeCycleListeners.forEach(listener -> listener.onServletContextRefreshed());
      }
    }
  }
}

代码示例来源:origin: com.dell.cpsd.common.messaging/common-rabbitmq

ApplicationContext context = event.getApplicationContext();

代码示例来源:origin: com.dell.cpsd/common-rabbitmq

ApplicationContext context = event.getApplicationContext();

相关文章

微信公众号

最新文章

更多