本文整理了Java中org.springframework.context.event.ContextRefreshedEvent
类的一些代码示例,展示了ContextRefreshedEvent
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ContextRefreshedEvent
类的具体详情如下:
包路径:org.springframework.context.event.ContextRefreshedEvent
类名称:ContextRefreshedEvent
[英]Event raised when an ApplicationContext gets initialized or refreshed.
[中]初始化或刷新ApplicationContext时引发的事件。
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@EventListener(ContextRefreshedEvent.class)
public void init(ContextRefreshedEvent event) {
try {
springSecurity = (FilterChainProxy) event.getApplicationContext().getBean("springSecurityFilterChain");
} catch (BeansException e) {
//do nothing
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Finish the refresh of this context, invoking the LifecycleProcessor's
* onRefresh() method and publishing the
* {@link org.springframework.context.event.ContextRefreshedEvent}.
*/
protected void finishRefresh() {
// Clear context-level resource caches (such as ASM metadata from scanning).
clearResourceCaches();
// Initialize lifecycle processor for this context.
initLifecycleProcessor();
// Propagate refresh to lifecycle processor first.
getLifecycleProcessor().onRefresh();
// Publish the final event.
publishEvent(new ContextRefreshedEvent(this));
// Participate in LiveBeansView MBean, if active.
LiveBeansView.registerApplicationContext(this);
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
if (context instanceof ConfigurableApplicationContext
&& context == event.getSource()) {
context.publishEvent(new ParentContextAvailableEvent(
(ConfigurableApplicationContext) context));
}
}
代码示例来源:origin: org.springframework.data/spring-data-geode
private QueryService getQueryService(ContextRefreshedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
String queryServiceBeanName = getQueryServiceBeanName();
return (applicationContext.containsBean(queryServiceBeanName)
? applicationContext.getBean(queryServiceBeanName, QueryService.class) : null);
}
代码示例来源:origin: pl.edu.icm.synat/synat-core-services-impl
@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
//FIXME
// StepParserStepFactoryBean returns wrong objectType, getBeansOfType return object that aren't TaskletSteps !!!
String[] beanNames = event.getApplicationContext().getBeanNamesForType(TaskletStep.class);
logger.info("Found {} steps", beanNames.length);
for (String beanName : beanNames) {
Object step = event.getApplicationContext().getBean(beanName);
if (step instanceof Step) {
replaceChunkProvider((Step) step);
}
}
}
代码示例来源:origin: changmingxie/tcc-transaction
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
if (applicationContext.getParent() == null) {
FactoryBuilder.registerBeanFactory(applicationContext.getBean(BeanFactory.class));
}
}
}
代码示例来源:origin: stackoverflow.com
public class MyBean implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
Collection<IMyInterface> implementors = context.getBeansOfType(IMyInterface.class).values();
}
代码示例来源:origin: shuzheng/zheng
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
if(null == contextRefreshedEvent.getApplicationContext().getParent()) {
LOGGER.debug(">>>>> spring初始化完毕 <<<<<");
Map<String, Object> baseServices = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(BaseService.class);
for(Object service : baseServices.values()) {
LOGGER.debug(">>>>> {}.initMapper()", service.getClass().getName());
Map<String, BaseInterface> baseInterfaceBeans = contextRefreshedEvent.getApplicationContext().getBeansOfType(BaseInterface.class);
for(Object service : baseInterfaceBeans.values()) {
LOGGER.debug(">>>>> {}.init()", service.getClass().getName());
代码示例来源:origin: spring-projects/spring-framework
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext() == this.applicationContext) {
this.contextRefreshed = true;
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
MyClass bean
= context
.getAutowireCapableBeanFactory()
.autowire(MyClass.class, Autowire.BY_NAME.value(), true);
...
}
代码示例来源:origin: org.jresearch.flexess.core/org.jresearch.flexess.core.impl
@Override
public void onApplicationEvent(final ContextRefreshedEvent evt) {
final ApplicationContext applicationContext = evt.getApplicationContext();
// do it once only for root context
if (applicationContext.getParent() == null) {
reloadModels(applicationContext);
}
}
代码示例来源:origin: OpenWiseSolutions/openhub-framework
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
Constraints.notNull(event, "event must not be null");
final PropertySource source = new DbPropertySource(DB_CONF_PROPERTY_SOURCE_NAME, paramService, includePatternStr);
ConfigurableEnvironment env = (ConfigurableEnvironment) event.getApplicationContext().getEnvironment();
env.getPropertySources().addLast(source);
LOG.debug("External DB configuration '{}' was added.", DB_CONF_PROPERTY_SOURCE_NAME);
}
}
代码示例来源:origin: alien4cloud/alien4cloud
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
if (!haEnabled && event.getApplicationContext() == alienContext) {
// child context may also dispatch context refresh event, we just want to process the ones of the main context.
log.info("HA is not enabled, this instance is the leader de facto");
alienContext.publishEvent(new HALeaderElectionEvent(this, true));
}
}
}
代码示例来源:origin: io.github.firefang/power-starter-permission
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
// 根容器为Spring容器
if (context.getParent() == null) {
Map<String, Object> beans = context.getBeansWithAnnotation(PermissionGroup.class);
List<PermissionDO> perms = new LinkedList<>();
for (Object bean : beans.values()) {
addPermsToList(bean, perms);
}
permissionService.upsertBatch(perms);
}
}
代码示例来源:origin: top.wboost/common-web
@Override
public void onRootApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
Map<String, Object> servicess = context.getBeansWithAnnotation(Service.class);
servicess.forEach((name, bean) -> {
Object target = AopUtils.getTarget(bean);
if (ClassUtils.isAssignable(BaseJpaServiceImpl.class, target.getClass())) {
autowired((BaseJpaServiceImpl) target);
}
});
}
代码示例来源:origin: mercyblitz/thinking-in-spring-boot-samples
@EventListener(ContextRefreshedEvent.class)
public void onContextRefreshed(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
ApplicationContext parentContext = context.getParent();
System.out.printf("当前管理端应用上下文 ID:%s,其双亲应用上下文 ID:%s\n",
context.getId(),
parentContext == null ? null : parentContext.getId()
);
}
}
代码示例来源:origin: com.holon-platform.jaxrs/holon-jaxrs-swagger-v2
@Bean
@Order(Integer.MAX_VALUE - 100)
public static ApplicationListener<ContextRefreshedEvent> jaxrsApiEndpointsDefinitionsV2InitializerApplicationListenerOnContextRefresh() {
return event -> {
API_ENDPOINT_DEFINITIONS
.getOrDefault(event.getApplicationContext().getClassLoader(), Collections.emptyList())
.forEach(d -> {
if (d.init()) {
LOGGER.info("Swagger V2 endpoint definition [" + d.getContextId() + "] initialized.");
}
});
};
}
代码示例来源:origin: stackoverflow.com
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext context = event.getApplicationContext();
System.out.println(context.getDisplayName());
}
代码示例来源:origin: mercyblitz/thinking-in-spring-boot-samples
@EventListener(ContextRefreshedEvent.class)
public void onContextRefreshedEvent(ContextRefreshedEvent event) {
ApplicationContext currentApplicationContext = event.getApplicationContext();
if (currentApplicationContext.equals(applicationContext)) { // 当应用上下文来自于服务端时
System.out.printf("当前应用上下文 ID :%s 执行 onContextRefreshedEvent() 方法\n",
currentApplicationContext.getId());
}
}
代码示例来源:origin: dsyer/spring-boot-aspectj
@EventListener
public void started(ContextRefreshedEvent event) {
System.err.println(message + ": " + event);
System.err.println("Beans: " + event.getApplicationContext().getBeanDefinitionCount());
}
内容来源于网络,如有侵权,请联系作者删除!