ApplicationContext 接口方法介绍
简单说下应用上下文接口的方法,
String getId(); //获取id
String getApplicationName(); //获取应用名
String getDisplayName(); //获取应用显示名称
long getStartupDate(); //获取应用启动时间
ApplicationContext getParent(); //获取上级应用上下文
AutowireCapableBeanFactory getAutowireCapableBeanFactory(); //实际获取(DefaultListableBeanFactory)
EnvironmentCapable 接口
ApplicationContext 继承 EnvironmentCapable接口
// 获取环境
Environment getEnvironment();
ListableBeanFactory 接口
ApplicationContext 继承 ListableBeanFactory接口
//是否包含bean名称的bean定义
boolean containsBeanDefinition(String beanName);
//获取Bean定义注册数量
int getBeanDefinitionCount();
//获取所有Bean定义名称的数组
String[] getBeanDefinitionNames();
//获取ResolvableType对象中type属性对应的所有bean名称(数组)
String[] getBeanNamesForType(ResolvableType type);
//获取class类型的bean名称(数组)
String[] getBeanNamesForType(Class<?> type);
//获取class类型的bean名称(数组). 包含单例、允许初始化的
String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit);
//获取class类型的bean映射
<T> Map<String, T> getBeansOfType(Class<T> type);
//获取class类型的bean映射. 包含单例、允许初始化的
<T> Map<String, T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit);
//通过注解class获取bean名称(数组)
String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);
//通过注解class获取bean监映射
Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType);
//通过bean名称, 及注解类型. 直接返回该bean的注解对象. 可以通过注解对象获取注解属性的值
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType);
HierarchicalBeanFactory 接口
ApplicationContext 继承HierarchicalBeanFactory接口
//获取上级工厂
BeanFactory getParentBeanFactory();
//是否包含bean
boolean containsLocalBean(String name);
MessageSource 接口
ApplicationContext 继承MessageSource接口(获取消息)
//获取消息信息
String getMessage(String code, Object[] args, String defaultMessage, Locale locale);
String getMessage(String code, Object[] args, Locale locale);
String getMessage(MessageSourceResolvable resolvable, Locale locale);
ApplicationEventPublisher 接口
ApplicationContext 继承ApplicationEventPublisher接口(事件发布)
//发布事件
void publishEvent(Object event);
//
default void publishEvent(ApplicationEvent event) {
publishEvent((Object) event);
}
ResourcePatternResolver 接口
ApplicationContext 继承ResourcePatternResolver接口(资源获取)
//根据路径获取资源对象. DefaultResourceLoader#getResources(String);
Resource[] getResources(String locationPattern);
//ResourceLoader接口
Resource getResource(String location);
//ResourceLoader接口
ClassLoader getClassLoader();