|
|
|
@ -297,19 +297,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the internal LifecycleProcessor used by the context. |
|
|
|
|
|
|
|
* @return the internal LifecycleProcessor (never <code>null</code>) |
|
|
|
|
|
|
|
* @throws IllegalStateException if the context has not been initialized yet |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private LifecycleProcessor getLifecycleProcessor() { |
|
|
|
|
|
|
|
if (this.lifecycleProcessor == null) { |
|
|
|
|
|
|
|
throw new IllegalStateException("LifecycleProcessor not initialized - " + |
|
|
|
|
|
|
|
"call 'refresh' before invoking lifecycle methods via the context: " + this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.lifecycleProcessor; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the internal ApplicationEventMulticaster used by the context. |
|
|
|
* Return the internal ApplicationEventMulticaster used by the context. |
|
|
|
* @return the internal ApplicationEventMulticaster (never <code>null</code>) |
|
|
|
* @return the internal ApplicationEventMulticaster (never <code>null</code>) |
|
|
|
@ -323,6 +310,19 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
return this.applicationEventMulticaster; |
|
|
|
return this.applicationEventMulticaster; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the internal LifecycleProcessor used by the context. |
|
|
|
|
|
|
|
* @return the internal LifecycleProcessor (never <code>null</code>) |
|
|
|
|
|
|
|
* @throws IllegalStateException if the context has not been initialized yet |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private LifecycleProcessor getLifecycleProcessor() { |
|
|
|
|
|
|
|
if (this.lifecycleProcessor == null) { |
|
|
|
|
|
|
|
throw new IllegalStateException("LifecycleProcessor not initialized - " + |
|
|
|
|
|
|
|
"call 'refresh' before invoking lifecycle methods via the context: " + this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.lifecycleProcessor; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the ResourcePatternResolver to use for resolving location patterns |
|
|
|
* Return the ResourcePatternResolver to use for resolving location patterns |
|
|
|
* into Resource instances. Default is a |
|
|
|
* into Resource instances. Default is a |
|
|
|
@ -400,15 +400,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
// Register bean processors that intercept bean creation.
|
|
|
|
// Register bean processors that intercept bean creation.
|
|
|
|
registerBeanPostProcessors(beanFactory); |
|
|
|
registerBeanPostProcessors(beanFactory); |
|
|
|
|
|
|
|
|
|
|
|
// Initialize conversion service for this context.
|
|
|
|
|
|
|
|
initConversionService(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize message source for this context.
|
|
|
|
// Initialize message source for this context.
|
|
|
|
initMessageSource(); |
|
|
|
initMessageSource(); |
|
|
|
|
|
|
|
|
|
|
|
// Initialize lifecycle processor for this context.
|
|
|
|
|
|
|
|
initLifecycleProcessor(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize event multicaster for this context.
|
|
|
|
// Initialize event multicaster for this context.
|
|
|
|
initApplicationEventMulticaster(); |
|
|
|
initApplicationEventMulticaster(); |
|
|
|
|
|
|
|
|
|
|
|
@ -494,6 +488,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this); |
|
|
|
beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this); |
|
|
|
beanFactory.registerResolvableDependency(ApplicationContext.class, this); |
|
|
|
beanFactory.registerResolvableDependency(ApplicationContext.class, this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize conversion service for this context.
|
|
|
|
|
|
|
|
if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME)) { |
|
|
|
|
|
|
|
beanFactory.setConversionService( |
|
|
|
|
|
|
|
beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Detect a LoadTimeWeaver and prepare for weaving, if found.
|
|
|
|
// Detect a LoadTimeWeaver and prepare for weaving, if found.
|
|
|
|
if (beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) { |
|
|
|
if (beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) { |
|
|
|
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory)); |
|
|
|
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory)); |
|
|
|
@ -704,16 +704,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Initialize the BeanFactory's ConversionService. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void initConversionService() { |
|
|
|
|
|
|
|
ConfigurableListableBeanFactory beanFactory = getBeanFactory(); |
|
|
|
|
|
|
|
if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME)) { |
|
|
|
|
|
|
|
beanFactory.setConversionService(beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initialize the MessageSource. |
|
|
|
* Initialize the MessageSource. |
|
|
|
* Use parent's if none defined in this context. |
|
|
|
* Use parent's if none defined in this context. |
|
|
|
@ -748,6 +738,31 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Initialize the ApplicationEventMulticaster. |
|
|
|
|
|
|
|
* Uses SimpleApplicationEventMulticaster if none defined in the context. |
|
|
|
|
|
|
|
* @see org.springframework.context.event.SimpleApplicationEventMulticaster |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void initApplicationEventMulticaster() { |
|
|
|
|
|
|
|
ConfigurableListableBeanFactory beanFactory = getBeanFactory(); |
|
|
|
|
|
|
|
if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) { |
|
|
|
|
|
|
|
this.applicationEventMulticaster = |
|
|
|
|
|
|
|
beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class); |
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory); |
|
|
|
|
|
|
|
beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster); |
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Unable to locate ApplicationEventMulticaster with name '" + |
|
|
|
|
|
|
|
APPLICATION_EVENT_MULTICASTER_BEAN_NAME + |
|
|
|
|
|
|
|
"': using default [" + this.applicationEventMulticaster + "]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initialize the LifecycleProcessor. |
|
|
|
* Initialize the LifecycleProcessor. |
|
|
|
* Uses DefaultLifecycleProcessor if none defined in the context. |
|
|
|
* Uses DefaultLifecycleProcessor if none defined in the context. |
|
|
|
@ -775,31 +790,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Initialize the ApplicationEventMulticaster. |
|
|
|
|
|
|
|
* Uses SimpleApplicationEventMulticaster if none defined in the context. |
|
|
|
|
|
|
|
* @see org.springframework.context.event.SimpleApplicationEventMulticaster |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void initApplicationEventMulticaster() { |
|
|
|
|
|
|
|
ConfigurableListableBeanFactory beanFactory = getBeanFactory(); |
|
|
|
|
|
|
|
if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) { |
|
|
|
|
|
|
|
this.applicationEventMulticaster = |
|
|
|
|
|
|
|
beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class); |
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory); |
|
|
|
|
|
|
|
beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster); |
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Unable to locate ApplicationEventMulticaster with name '" + |
|
|
|
|
|
|
|
APPLICATION_EVENT_MULTICASTER_BEAN_NAME + |
|
|
|
|
|
|
|
"': using default [" + this.applicationEventMulticaster + "]"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Template method which can be overridden to add context-specific refresh work. |
|
|
|
* Template method which can be overridden to add context-specific refresh work. |
|
|
|
* Called on initialization of special beans, before instantiation of singletons. |
|
|
|
* Called on initialization of special beans, before instantiation of singletons. |
|
|
|
@ -858,7 +848,11 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
* {@link org.springframework.context.event.ContextRefreshedEvent}. |
|
|
|
* {@link org.springframework.context.event.ContextRefreshedEvent}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void finishRefresh() { |
|
|
|
protected void finishRefresh() { |
|
|
|
this.lifecycleProcessor.onRefresh(); |
|
|
|
// Initialize lifecycle processor for this context.
|
|
|
|
|
|
|
|
initLifecycleProcessor(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Propagate refresh to lifecycle processor first.
|
|
|
|
|
|
|
|
getLifecycleProcessor().onRefresh(); |
|
|
|
|
|
|
|
|
|
|
|
// Publish the final event.
|
|
|
|
// Publish the final event.
|
|
|
|
publishEvent(new ContextRefreshedEvent(this)); |
|
|
|
publishEvent(new ContextRefreshedEvent(this)); |
|
|
|
|