public class StaticApplicationContext extends GenericApplicationContext
ApplicationContext
implementation
which supports programmatic registration of beans and messages,
rather than reading bean definitions from external configuration sources.
Mainly useful for testing.registerSingleton(java.lang.String, java.lang.Class<?>)
,
registerPrototype(java.lang.String, java.lang.Class<?>)
,
GenericApplicationContext.registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
,
AbstractApplicationContext.refresh()
DefaultResourceLoader.ClassPathContextResource
Modifier and Type | Field and Description |
---|---|
private StaticMessageSource |
staticMessageSource |
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME
CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME
FACTORY_BEAN_PREFIX
CLASSPATH_ALL_URL_PREFIX
CLASSPATH_URL_PREFIX
Constructor and Description |
---|
StaticApplicationContext()
Create a new StaticApplicationContext.
|
StaticApplicationContext(ApplicationContext parent)
Create a new StaticApplicationContext with the given parent.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessage(java.lang.String code,
java.util.Locale locale,
java.lang.String defaultMessage)
Associate the given message with the given code.
|
protected void |
assertBeanFactoryActive()
Overridden to turn it into a no-op, to be more lenient towards test cases.
|
StaticMessageSource |
getStaticMessageSource()
Return the internal StaticMessageSource used by this context.
|
void |
registerPrototype(java.lang.String name,
java.lang.Class<?> clazz)
Register a prototype bean with the underlying bean factory.
|
void |
registerPrototype(java.lang.String name,
java.lang.Class<?> clazz,
MutablePropertyValues pvs)
Register a prototype bean with the underlying bean factory.
|
void |
registerSingleton(java.lang.String name,
java.lang.Class<?> clazz)
Register a singleton bean with the underlying bean factory.
|
void |
registerSingleton(java.lang.String name,
java.lang.Class<?> clazz,
MutablePropertyValues pvs)
Register a singleton bean with the underlying bean factory.
|
cancelRefresh, closeBeanFactory, getAutowireCapableBeanFactory, getBeanDefinition, getBeanFactory, getClassLoader, getDefaultListableBeanFactory, getResource, getResources, isAlias, isBeanNameInUse, refreshBeanFactory, registerAlias, registerBean, registerBean, registerBean, registerBean, registerBean, registerBean, registerBeanDefinition, removeAlias, removeBeanDefinition, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setClassLoader, setParent, setResourceLoader
addApplicationListener, addBeanFactoryPostProcessor, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroy, destroyBeans, doClose, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getAliases, getApplicationEventMulticaster, getApplicationListeners, getApplicationName, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getLifecycleProcessor, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, resetCommonCaches, setDisplayName, setEnvironment, setId, start, stop, toString
addProtocolResolver, clearResourceCaches, getProtocolResolvers, getResourceByPath, getResourceCache
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames
getAliases
addProtocolResolver
private final StaticMessageSource staticMessageSource
public StaticApplicationContext() throws BeansException
BeansException
registerSingleton(java.lang.String, java.lang.Class<?>)
,
registerPrototype(java.lang.String, java.lang.Class<?>)
,
GenericApplicationContext.registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
,
AbstractApplicationContext.refresh()
public StaticApplicationContext(@Nullable ApplicationContext parent) throws BeansException
BeansException
registerSingleton(java.lang.String, java.lang.Class<?>)
,
registerPrototype(java.lang.String, java.lang.Class<?>)
,
GenericApplicationContext.registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)
,
AbstractApplicationContext.refresh()
protected void assertBeanFactoryActive()
assertBeanFactoryActive
in class AbstractApplicationContext
public final StaticMessageSource getStaticMessageSource()
public void registerSingleton(java.lang.String name, java.lang.Class<?> clazz) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void registerSingleton(java.lang.String name, java.lang.Class<?> clazz, MutablePropertyValues pvs) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void registerPrototype(java.lang.String name, java.lang.Class<?> clazz) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void registerPrototype(java.lang.String name, java.lang.Class<?> clazz, MutablePropertyValues pvs) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void addMessage(java.lang.String code, java.util.Locale locale, java.lang.String defaultMessage)
code
- lookup codelocale
- locale message should be found withindefaultMessage
- message associated with this lookup codegetStaticMessageSource()