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
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, SHUTDOWN_HOOK_THREAD_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(String code,
Locale locale,
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(String name,
Class<?> clazz)
Register a prototype bean with the underlying bean factory.
|
void |
registerPrototype(String name,
Class<?> clazz,
MutablePropertyValues pvs)
Register a prototype bean with the underlying bean factory.
|
void |
registerSingleton(String name,
Class<?> clazz)
Register a singleton bean with the underlying bean factory.
|
void |
registerSingleton(String name,
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, getApplicationListeners, getApplicationName, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getStartupDate, getType, 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
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(String name, Class<?> clazz) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void registerSingleton(String name, Class<?> clazz, MutablePropertyValues pvs) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void registerPrototype(String name, Class<?> clazz) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void registerPrototype(String name, Class<?> clazz, MutablePropertyValues pvs) throws BeansException
For more advanced needs, register with the underlying BeanFactory directly.
BeansException
GenericApplicationContext.getDefaultListableBeanFactory()
public void addMessage(String code, Locale locale, String defaultMessage)
code
- lookup codelocale
- locale message should be found withindefaultMessage
- message associated with this lookup codegetStaticMessageSource()