當前位置: 首頁>>代碼示例>>Java>>正文


Java ContextRefreshedEvent.getApplicationContext方法代碼示例

本文整理匯總了Java中org.springframework.context.event.ContextRefreshedEvent.getApplicationContext方法的典型用法代碼示例。如果您正苦於以下問題:Java ContextRefreshedEvent.getApplicationContext方法的具體用法?Java ContextRefreshedEvent.getApplicationContext怎麽用?Java ContextRefreshedEvent.getApplicationContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.context.event.ContextRefreshedEvent的用法示例。


在下文中一共展示了ContextRefreshedEvent.getApplicationContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
    logger.info("ContextRefreshedEvent");

    ApplicationContext applicationContext = event.getApplicationContext();
    logger.info("Found " + services.size() + " services");

    ErraiServiceSingleton.registerInitCallback(new ErraiServiceSingleton.ErraiInitCallback() {
        @SuppressWarnings("rawtypes")
        @Override
        public void onInit(ErraiService service) {
            logger.info("Subscribing " + services.size() + " services.");
            for (ServiceImplementation serviceImplementation : services) {
                subscribe(applicationContext, service, serviceImplementation);
            }
        }
    });
}
 
開發者ID:expansel,項目名稱:errai-spring-server,代碼行數:19,代碼來源:ErraiApplicationListener.java

示例2: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ApplicationEvent event)
{
    if (event instanceof ContextRefreshedEvent)
    {
        ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent)event;
        ApplicationContext refreshContext = refreshEvent.getApplicationContext();
        if (refreshContext != null && refreshContext.equals(applicationContext))
        {
            RunAsWork<Object> work = new RunAsWork<Object>()
            {
                public Object doWork() throws Exception
                {
                    reset();
                    return null;
                }
            };
            AuthenticationUtil.runAs(work, AuthenticationUtil.getSystemUserName());
        }
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:22,代碼來源:RepositoryContainer.java

示例3: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

    try {
        context = contextRefreshedEvent.getApplicationContext();
        SysConfig sysConfig = context.getBean(SysConfig.class);
        // 接收UDP消息並保存至redis中
        UdpServer udpServer = (UdpServer) StartupEvent.getBean(UdpServer.class);
        // 獲取屬性列表中的端口號,運行 UDP 服務器。
        udpServer.run(sysConfig.getUdpReceivePort());

        // 這裏可以開啟多個線程去執行不同的任務


    } catch (Exception e) {
        logger.error("Exception", e);
    }
}
 
開發者ID:jeikerxiao,項目名稱:SpringBootStudy,代碼行數:19,代碼來源:StartupEvent.java

示例4: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext)event.getApplicationContext();
    Map<String,Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(ThriftServiceApi.class);
    ServiceMap serviceMap=new ServiceMap();
    for(String name:beansWithAnnotation.keySet()){
        Object obj = beansWithAnnotation.get(name);
        Class[] interfaces=obj.getClass().getInterfaces();
        for(Class i:interfaces)
            if(i.getAnnotation(ThriftServiceApi.class)!=null){
                serviceMap.addService(i.getName(),obj);
            }

    }
    applicationContext.getBeanFactory().registerSingleton(serviceMap.getClass().getName(),serviceMap);
}
 
開發者ID:somewhereMrli,項目名稱:albedo-thrift,代碼行數:17,代碼來源:ServiceMapListener.java

示例5: start

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
public void start(ContextRefreshedEvent event) {
    if (event.getApplicationContext() == this.context) {
        if (this.eager && this.registry != null) {
            for (String name : this.context.getBeanDefinitionNames()) {
                BeanDefinition definition = this.registry.getBeanDefinition(name);
                if (this.getName().equals(definition.getScope())
                        && !definition.isLazyInit()) {
                    this.context.getBean(name);
                }
            }
        }
    }
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:14,代碼來源:VersionRefreshScope.java

示例6: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (event.getApplicationContext() == this.applicationContext) {
        registerConfigWatchers();
        watch();
    }
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:8,代碼來源:ConfigContext.java

示例7: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
public void onApplicationEvent(ApplicationEvent event)
{
    if (event instanceof ContextRefreshedEvent)
    {
        ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent)event;
        ApplicationContext refreshContext = refreshEvent.getApplicationContext();
        if (refreshContext != null && refreshContext.equals(applicationContext))
        {
            // Initialize the bean
          
            init();
        }
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:15,代碼來源:AbstractServerConfigurationBean.java

示例8: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:39,代碼來源:ScheduledAnnotationBeanPostProcessor.java

示例9: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
/**
 * Actually schedule the tasks at the right time of the context lifecycle,
 * if we're running within an ApplicationContext.
 */
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
	if (event.getApplicationContext() != this.applicationContext) {
		return;
	}
	scheduleTasks();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:ContextLifecycleScheduledTaskRegistrar.java

示例10: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    synchronized (lock) {
        if (initialled) {
            return;
        } else {
            ApplicationContext applicationContext = event.getApplicationContext();
            Map<String, ServiceBean> instances = applicationContext.getBeansOfType(ServiceBean.class);
            if (!instances.isEmpty()) {
                ConfigBean configBean = applicationContext.getBean(ConfigBean.class);
                this.thrallProperties = configBean;
                RpcServiceConfig rpcSerivceConfig = new RpcServiceConfig();
                this.addRegistyAddress(rpcSerivceConfig);
                rpcSerivceConfig.setApplication(thrallProperties.getApplication());
                this.addHostAndPort(rpcSerivceConfig);
                rpcSerivceConfig.setMonitorinterval(thrallProperties.getMonitorinterval());
                for (Map.Entry<String, ServiceBean> entry : instances.entrySet()) {
                    ServiceBean serviceBean = entry.getValue();
                    rpcSerivceConfig.addServiceDefinition(serviceBean.getServiceName(), serviceBean.getGroup(),
                                                          serviceBean.getVersion(), serviceBean.getRef());
                }
                this.rpcService = rpcSerivceConfig;
                initialled = true;
                rpcSerivceConfig.export();
            }
        }

    }

}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:31,代碼來源:ServiceBean.java

示例11: loadProcessor

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
/**
 * 處理所有處理器排序以及分組邏輯
 */
private void loadProcessor(ContextRefreshedEvent event) {
  ApplicationContext ac = event.getApplicationContext();
  Map<String, FileUploadProcessor> beans = ac.getBeansOfType(FileUploadProcessor.class);
  if (beans != null && beans.size() > 0) {
    /**
     * 分組
     * public M -------
     * group1 1 ---
     *        2 ---
     *        3 ---
     * group2 1 ---
     *        2 ---
     *        3 ---        
     */
    
    for (Map.Entry<String, FileUploadProcessor> entry : beans.entrySet()) {
      
      FileUploadProcessor processor = entry.getValue();
      FileUploadProcessor target = null;//非代理的處理器
      
      
      try {
         target = (FileUploadProcessor) AopTargetUtils.getTarget(processor);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
      
      ProcessorChannel processorGroup = target.getClass().getAnnotation(ProcessorChannel.class);
      
      String group = AbstractChannelProcessor.KEY;
      // 取出自定義分組
      if (processorGroup != null){
        group = processorGroup.channel();
      }else{
        //取出公共的注冊鏈
        //默認就是公共分組了
      }
      TreeMap<Integer, LinkedList<FileUploadProcessor>> linkedTreeMap = processorLogicDefination.get(group);
      Integer orderIndex = Integer.MAX_VALUE;
      ProcessorOrder processorOrder = target.getClass().getAnnotation(ProcessorOrder.class);
      if (processorOrder != null) {
        orderIndex = processorOrder.order();
      }
      
      if (linkedTreeMap == null) {
        linkedTreeMap = new TreeMap<Integer, LinkedList<FileUploadProcessor>>();
        processorLogicDefination.put(group, linkedTreeMap);
      }
      
      LinkedList<FileUploadProcessor> storage = linkedTreeMap.get(orderIndex);
      if (storage == null) {
        storage = new LinkedList<FileUploadProcessor>();
        linkedTreeMap.put(orderIndex, storage);
      }
      storage.add(processor);
    }
    // linked

  }
}
 
開發者ID:devpage,項目名稱:fastdfs-quickstart,代碼行數:64,代碼來源:FileProcessFactory.java

示例12: onBootstrap

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
protected void onBootstrap(ApplicationEvent event)
{
    logger.info("Bootstapping the API");
    ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent)event;
    ApplicationContext ac = refreshEvent.getApplicationContext();
    Map<String, Object> entityResourceBeans = ac.getBeansWithAnnotation(EntityResource.class);
    Map<String, Object> relationResourceBeans = ac.getBeansWithAnnotation(RelationshipResource.class);
    apiDictionary.setDictionary(ResourceDictionaryBuilder.build(entityResourceBeans.values(), relationResourceBeans.values()));
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:11,代碼來源:ApiBootstrap.java

示例13: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        ApplicationContext applicationContext = event.getApplicationContext();
        final ApplicationPersistenceService applicationPersistenceService =
                applicationContext.getBean(ApplicationPersistenceService.class);
        applicationPersistenceService.getApplications(); // read nothing.
    }      
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:10,代碼來源:PersistenceApplicationListener.java

示例14: handleEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
/**
 * Implementation of the spring event listener interface.
 *
 * @param event the spring event from the application
 */
@EventListener
public void handleEvent(ApplicationEvent event) {
    // checking for start up event
    // order of events is BrokerAvailabilityEvent -> ContextRefreshedEvent[parent=null] -> ContextRefreshedEvent[with non-null parent]
    // so wait until the latest event is received: ContextRefreshedEvent[with non-null parent]

    // skip the BrokerAvailabilityEvent, and ignore all other events (SessionConnectedEvent, ServletRequestHandledEvent, ContextClosedEvent, etc.)
    if (!(event instanceof ContextRefreshedEvent)) {
        LOGGER.debug("Expecting ContextRefreshedEvent. Skipping.");
        return;
    }

    LOGGER.info("Received ContextRefreshedEvent {}", event);

    ContextRefreshedEvent crEvent = (ContextRefreshedEvent) event;
    final ApplicationContext applicationContext = crEvent.getApplicationContext();
    // skip the ContextRefreshedEvent[parent=null] but check for non-null context first
    if (null == applicationContext) {
        LOGGER.debug("Expecting non-null ApplicationContext. Skipping.");
        return;
    }
    if (null == applicationContext.getParent()) {
        LOGGER.debug("Expecting non-null ApplicationContext parent. Skipping.");
        return;
    }

    processBootstrapConfiguration();
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:34,代碼來源:ApplicationContextListener.java

示例15: onApplicationEvent

import org.springframework.context.event.ContextRefreshedEvent; //導入方法依賴的package包/類
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    ApplicationContext applicationContext = event.getApplicationContext();
    AsyncTaskService asyncTaskService = applicationContext.getBean(AsyncTaskService.class);
    int threadNum = Integer.parseInt(applicationContext.getEnvironment().getProperty("consumer.thread.num"));
    for (int i = 0; i < threadNum; i++) {
        asyncTaskService.executeAsyncTask(i);
    }
}
 
開發者ID:V-I-C-T-O-R,項目名稱:DataM,代碼行數:10,代碼來源:ApplicationStartup.java


注:本文中的org.springframework.context.event.ContextRefreshedEvent.getApplicationContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。