本文整理汇总了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);
}
}
});
}
示例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());
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
}
}
示例6: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext() == this.applicationContext) {
registerConfigWatchers();
watch();
}
}
示例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();
}
}
}
示例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();
}
示例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();
}
示例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();
}
}
}
}
示例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
}
}
示例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()));
}
示例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.
}
}
示例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();
}
示例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);
}
}