当前位置: 首页>>代码示例>>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;未经允许,请勿转载。