Exemple #1
0
 @Override
 public void onApplicationEvent(ContextRefreshedEvent event) {
   // 防止重复执行。
   if (event.getApplicationContext().getParent() == null) {
     this.token = weixinProxy.httpToken();
   }
 }
 @Override
 public void onApplicationEvent(ContextRefreshedEvent evt) {
   logger.debug("4.1 => MyApplicationListener.onApplicationEvent");
   if (evt.getApplicationContext().getParent() == null) {
     logger.debug("4.2 => MyApplicationListener.onApplicationEvent");
   }
 }
 /**
  * Listener method which waits for a {@link ContextRefreshedEvent} and then extracts the {@link
  * SessionFactory} from the {@link ApplicationContext} and pases it to {@link
  * #setSessionFactory(SessionFactory)}.
  */
 @Override
 public void handleContextRefreshedEvent(ContextRefreshedEvent cre) {
   ApplicationContext ctx = cre.getApplicationContext();
   if (ctx.containsBean("sessionFactory")) {
     SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");
     setSessionFactory(sessionFactory);
   } else {
     log.warn("No session factory found. Cannot initialize");
   }
 }
 @Override
 public void onApplicationEvent(ContextRefreshedEvent event) {
   if (!this.lazyConnect
       && event.getApplicationContext().equals(getApplicationContext())
       && this.amqpTemplate instanceof RabbitTemplate) {
     ConnectionFactory connectionFactory =
         ((RabbitTemplate) this.amqpTemplate).getConnectionFactory();
     if (connectionFactory != null) {
       try {
         Connection connection = connectionFactory.createConnection();
         if (connection != null) {
           connection.close();
         }
       } catch (RuntimeException e) {
         logger.error("Failed to eagerly establish the connection.", e);
       }
     }
   }
 }
  @Override
  public void onApplicationEvent(ContextRefreshedEvent event) {
    if (event.getApplicationContext() != this.applicationContext) {
      return;
    }

    if (this.scheduler != null) {
      this.registrar.setScheduler(this.scheduler);
    }

    Map<String, SchedulingConfigurer> configurers =
        this.applicationContext.getBeansOfType(SchedulingConfigurer.class);
    for (SchedulingConfigurer configurer : configurers.values()) {
      configurer.configureTasks(this.registrar);
    }

    if (this.registrar.hasTasks() && this.registrar.getScheduler() == null) {
      Map<String, ? super Object> schedulers = new HashMap<String, Object>();
      schedulers.putAll(this.applicationContext.getBeansOfType(TaskScheduler.class));
      schedulers.putAll(this.applicationContext.getBeansOfType(ScheduledExecutorService.class));
      if (schedulers.size() == 0) {
        // do nothing -> fall back to default scheduler
      } else if (schedulers.size() == 1) {
        this.registrar.setScheduler(schedulers.values().iterator().next());
      } else if (schedulers.size() >= 2) {
        throw new IllegalStateException(
            "More than one TaskScheduler and/or ScheduledExecutorService  "
                + "exist within the context. Remove all but one of the beans; or implement the "
                + "SchedulingConfigurer interface and call ScheduledTaskRegistrar#setScheduler "
                + "explicitly within the configureTasks() callback. Found the following beans: "
                + schedulers.keySet());
      }
    }

    this.registrar.afterPropertiesSet();
  }
 /**
  * Callback that receives refresh events from this servlet's WebApplicationContext.
  *
  * <p>The default implementation calls {@link #onRefresh}, triggering a refresh of this servlet's
  * context-dependent state.
  *
  * @param event the incoming ApplicationContext event
  */
 public void onApplicationEvent(ContextRefreshedEvent event) {
   this.refreshEventReceived = true;
   onRefresh(event.getApplicationContext());
 }