本文整理汇总了Java中org.springframework.context.event.ContextRefreshedEvent类的典型用法代码示例。如果您正苦于以下问题:Java ContextRefreshedEvent类的具体用法?Java ContextRefreshedEvent怎么用?Java ContextRefreshedEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextRefreshedEvent类属于org.springframework.context.event包,在下文中一共展示了ContextRefreshedEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event.getClass() == ContextRefreshedEvent.class) {
logger.info("register url: " + infoHolder.taskProtocolUrl());
extensionLoader.loadExtension(Registry.class).doRegister(infoHolder.taskProtocolUrl());
try {
extensionLoader.loadExtension(ProtocolFactory.class).server().openServer(infoHolder.taskProtocolUrl());
} catch (Exception e) {
throw new RuntimeException(e);
}
sandbox.configSandbox();
} else if (event.getClass() == ContextClosedEvent.class) {
logger.info("unregister url: " + infoHolder.taskProtocolUrl());
extensionLoader.loadExtension(Registry.class).unRegister(infoHolder.taskProtocolUrl());
extensionLoader.loadExtension(ProtocolFactory.class).server().close();
}
}
示例2: init
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
log.info("start data initialization ...");
this.posts
.deleteAll()
.thenMany(
Flux
.range(1, 1000)
.flatMap(
num -> this.posts.save(Post.builder().title("Title" + num).content("content of " + "Title" + num).build())
)
)
.log()
.subscribe(
null,
null,
() -> log.info("done initialization...")
);
}
示例3: init
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
log.info("start data initialization ...");
this.posts
.deleteAll()
.thenMany(
Flux
.just("Post one", "Post two")
.flatMap(
title -> this.posts.save(Post.builder().title(title).content("content of " + title).build())
)
)
.log()
.subscribe(
null,
null,
() -> log.info("done initialization...")
);
}
示例4: init
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
log.info("start data initialization ...");
this.posts
.deleteAll()
.thenMany(
Flux
.range(1, 100)
.flatMap(
num -> this.posts.save(Post.builder().title("Title" + num).content("content of " + "Title" + num).build())
)
)
.log()
.subscribe(
null,
null,
() -> log.info("done initialization...")
);
}
示例5: init
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
log.info("start data initialization ...");
this.posts
.deleteAll()
.thenMany(
Flux
.just("Post one", "Post two")
.flatMap(
title -> this.posts.save(Post.builder().id(UUID.randomUUID().toString()).title(title).content("content of " + title).build())
)
)
.log()
.subscribe(
null,
null,
() -> log.info("done initialization...")
);
}
示例6: contextRefreshedEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
/**
* Run setup when application starts.
*/
@EventListener(ContextRefreshedEvent.class)
public void contextRefreshedEvent() {
logger.info("Running setup");
if (userRepository.count() == 0) {
logger.info("No users have been configured, creating default user");
User user = new User(defaultUsername,
defaultPassword,
Collections.singleton("ROLE_" + WebSecurityConfig.Roles.ADMIN));
userRepository.save(user);
logger.info("Created user \"{}\" with password \"{}\". Change this password for security reasons!",
defaultUsername,
defaultPassword);
}
logger.info("Setup completed");
}
示例7: 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);
}
示例8: init
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
/**
* Start the scheduler.
* Method called after Spring has finished initializing the Application Context, so that YadaPersistentEnums have been initialized.
* @param event
* @throws Exception
*/
@EventListener
public void init(ContextRefreshedEvent event) {
if (initialized.getAndSet(true)) {
return;
}
// It is itself scheduled by a TaskScheduler configured in YadaAppConfig and run every config/yada/jobSchedulerPeriodMillis milliseconds
log.debug("init called");
long period = config.getYadaJobSchedulerPeriod();
if (period>0) {
// Disable any job that is already RUNNING but jobRecoverable is false
yadaJobDao.setUnrecoverableJobState();
// Recover any job that is still in the RUNNING state and its group is not paused
List<YadaJob> recoverableJobs = yadaJobDao.getRecoverableJobs();
for (YadaJob yadaJob : recoverableJobs) {
yadaJob.setRecovered(true);
yadaJob.setJobStartTime(new Date()); // Needed to prevent stale cleaning
yadaJobRepository.save(yadaJob);
yadaJobScheduler.runJob(yadaJob.getId());
}
// Scheduling the YadaJobScheduler according to the configured period
yadaJobSchedulerTaskScheduler.scheduleAtFixedRate(yadaJobScheduler, new Date(System.currentTimeMillis() + 10000), period);
} else {
log.info("YadaJobScheduler not started");
}
}
示例9: 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);
}
}
});
}
示例10: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextClosedEvent) {
enabled = false;
return;
}
if (event instanceof ContextRefreshedEvent) {
initialized = true;
return;
}
if (event instanceof OsgiServiceDependencyWaitStartingEvent) {
if (enabled) {
OsgiServiceDependencyWaitStartingEvent evt = (OsgiServiceDependencyWaitStartingEvent) event;
String[] filter = new String[] { evt.getServiceDependency().getServiceFilter().toString() };
BlueprintEvent waitingEvent =
new BlueprintEvent(BlueprintEvent.WAITING, bundleContext.getBundle(), extenderBundle,
filter);
listenerManager.blueprintEvent(waitingEvent);
dispatcher.waiting(waitingEvent);
}
return;
}
}
示例11: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
// root application context
if(null == contextRefreshedEvent.getApplicationContext().getParent()) {
logger.debug(">>>>> spring初始化完毕 <<<<<");
// spring初始化完毕后,通过反射调用所有使用BaseService注解的initMapper方法
Map<String, Object> baseServices = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(BaseService.class);
for(Map.Entry<String, Object> entry : baseServices.entrySet()){
System.out.println(entry.getKey() + "," + entry.getValue());
}
for(Object service : baseServices.values()) {
logger.debug(">>>>> {}.initMapper()", service.getClass().getName());
try {
Method initMapper = service.getClass().getMethod("initMapper");
initMapper.invoke(service);
} catch (Exception e) {
logger.error("初始化BaseService的initMapper方法异常", e);
e.printStackTrace();
}
}
}
}
示例12: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//模块执行完会执行该方法
logger.debug("开始扫描模块");
//获取所有有模块注解的对象
Map<String, Object> beans = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(Module.class);
List<com.carl.wolf.core.bean.Module> modules = new ArrayList<>();
for (Object value : beans.values()) {
try {
//处理获取模块并且添加到容器
if (scanStrategy.support(value)) {
modules.add(scanStrategy.process(value));
}
} catch (ModuleScanException e) {
logger.error("模块扫描异常", e);
}
}
}
示例13: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent ( ContextRefreshedEvent event ) {
final RequestMappingHandlerMapping requestMappingHandlerMapping =
applicationContext.getBean( RequestMappingHandlerMapping.class );
final Map< RequestMappingInfo, HandlerMethod > handlerMethods =
requestMappingHandlerMapping.getHandlerMethods();
this.handlerMethods = handlerMethods;
handlerMethods.keySet().forEach( mappingInfo -> {
Map< Set< String >, Set< RequestMethod > > mapping = Collections.singletonMap(
mappingInfo.getPatternsCondition().getPatterns() ,
this.getMethods( mappingInfo.getMethodsCondition().getMethods() )
);
requestMappingInfos.add( mapping );
} );
requestMappingUris.addAll(
handlerMethods.keySet()
.parallelStream()
.map( mappingInfo -> mappingInfo.getPatternsCondition().getPatterns() )
.collect( Collectors.toList() )
);
}
示例14: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// Spring context initialized trigger
if (event.getApplicationContext().getParent() == null) {
loadProcessor(event);
}
// spring web root initialized trigger
if (event.getApplicationContext().getDisplayName().equals("Root WebApplicationContext")) {
if (processorLogicDefination.size()==0) {
loadProcessor(event);
}
}
System.out.println(JSON.toJSONString(processorLogicDefination,true));
}
示例15: onApplicationEvent
import org.springframework.context.event.ContextRefreshedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if(event.getApplicationContext().getParent() == null){
//需要执行的逻辑代码,当spring容器初始化完成后就会执行该方法。
System.out.println("spring 加载完毕..");
new ApplicationFactory().setApplicationContext(event.getApplicationContext());
try {
NettyServer.getInstance().start();
} catch (Exception e) {
e.printStackTrace();
}
}
}