本文整理匯總了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();
}
}
}