接口 ApplicationContext
- 所有超级接口:
ApplicationEventPublisher
,BeanFactory
,EnvironmentCapable
,HierarchicalBeanFactory
,ListableBeanFactory
,MessageSource
,ResourceLoader
,ResourcePatternResolver
- 所有已知实现类:
AbstractApplicationContext
,AbstractRefreshableApplicationContext
,AbstractRefreshableConfigApplicationContext
,AbstractRefreshableWebApplicationContext
,AbstractXmlApplicationContext
,AnnotationConfigApplicationContext
,AnnotationConfigWebApplicationContext
,ClassPathXmlApplicationContext
,FileSystemXmlApplicationContext
,GenericApplicationContext
,GenericGroovyApplicationContext
,GenericWebApplicationContext
,GenericXmlApplicationContext
,GroovyWebApplicationContext
,ResourceAdapterApplicationContext
,StaticApplicationContext
,StaticWebApplicationContext
,XmlWebApplicationContext
public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory, MessageSource, ApplicationEventPublisher, ResourcePatternResolver
Central interface to provide configuration for an application. This is read-only while the application is running, but may be reloaded if the implementation supports this.An ApplicationContext provides:
- Bean factory methods for accessing application components. Inherited from
ListableBeanFactory
. - The ability to load file resources in a generic fashion. Inherited from the
ResourceLoader
interface. - The ability to publish events to registered listeners. Inherited from the
ApplicationEventPublisher
interface. - The ability to resolve messages, supporting internationalization. Inherited from the
MessageSource
interface. - Inheritance from a parent context. Definitions in a descendant context will always take priority. This means, for example, that a single parent context can be used by an entire web application, while each servlet has its own child context that is independent of that of any other servlet.
In addition to standard
BeanFactory
lifecycle capabilities, ApplicationContext implementations detect and invokeApplicationContextAware
beans as well asResourceLoaderAware
,ApplicationEventPublisherAware
andMessageSourceAware
beans.- 作者:
- Rod Johnson, Juergen Hoeller
- 另请参阅:
ConfigurableApplicationContext
,BeanFactory
,ResourceLoader
字段概要
从接口继承的字段 org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
从接口继承的字段 org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
从接口继承的字段 org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 String
getApplicationName()
Return a name for the deployed application that this context belongs to.AutowireCapableBeanFactory
getAutowireCapableBeanFactory()
Expose AutowireCapableBeanFactory functionality for this context.String
getDisplayName()
Return a friendly name for this context.String
getId()
Return the unique id of this application context.ApplicationContext
getParent()
Return the parent context, ornull
if there is no parent and this is the root of the context hierarchy.long
getStartupDate()
Return the timestamp when this context was first loaded.从接口继承的方法 org.springframework.context.ApplicationEventPublisher
publishEvent, publishEvent
从接口继承的方法 org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getType, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch
从接口继承的方法 org.springframework.core.env.EnvironmentCapable
getEnvironment
从接口继承的方法 org.springframework.beans.factory.HierarchicalBeanFactory
containsLocalBean, getParentBeanFactory
从接口继承的方法 org.springframework.beans.factory.ListableBeanFactory
containsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation
从接口继承的方法 org.springframework.context.MessageSource
getMessage, getMessage, getMessage
从接口继承的方法 org.springframework.core.io.ResourceLoader
getClassLoader, getResource
从接口继承的方法 org.springframework.core.io.support.ResourcePatternResolver
getResources
方法详细资料
getId
@Nullable String getId()
Return the unique id of this application context.- 返回:
- the unique id of the context, or
null
if none
getApplicationName
String getApplicationName()
Return a name for the deployed application that this context belongs to.- 返回:
- a name for the deployed application, or the empty String by default
getDisplayName
String getDisplayName()
Return a friendly name for this context.- 返回:
- a display name for this context (never
null
)
getStartupDate
long getStartupDate()
Return the timestamp when this context was first loaded.- 返回:
- the timestamp (ms) when this context was first loaded
getParent
@Nullable ApplicationContext getParent()
Return the parent context, ornull
if there is no parent and this is the root of the context hierarchy.- 返回:
- the parent context, or
null
if there is no parent
getAutowireCapableBeanFactory
AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException
Expose AutowireCapableBeanFactory functionality for this context.This is not typically used by application code, except for the purpose of initializing bean instances that live outside of the application context, applying the Spring bean lifecycle (fully or partly) to them.
Alternatively, the internal BeanFactory exposed by the
ConfigurableApplicationContext
interface offers access to theAutowireCapableBeanFactory
interface too. The present method mainly serves as a convenient, specific facility on the ApplicationContext interface.NOTE: As of 4.2, this method will consistently throw IllegalStateException after the application context has been closed. In current Spring Framework versions, only refreshable application contexts behave that way; as of 4.2, all application context implementations will be required to comply.
- 返回:
- the AutowireCapableBeanFactory for this context
- 抛出:
IllegalStateException
- if the context does not support theAutowireCapableBeanFactory
interface, or does not hold an autowire-capable bean factory yet (e.g. ifrefresh()
has never been called), or if the context has been closed already- 另请参阅:
ConfigurableApplicationContext.refresh()
,ConfigurableApplicationContext.getBeanFactory()