ApplicationContext体系:

ConfigurableApplicationContext接口中定义了一些基本操作,比如设置上下文ID,设置父应用上下文,添加监听器和刷新容器相关的操作等。

源码如下:

public interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle, Closeable {

	
	String CONFIG_LOCATION_DELIMITERS = ",; \t\n";

	
	String CONVERSION_SERVICE_BEAN_NAME = "conversionService";

	String LOAD_TIME_WEAVER_BEAN_NAME = "loadTimeWeaver";

	String ENVIRONMENT_BEAN_NAME = "environment";

	
	String SYSTEM_PROPERTIES_BEAN_NAME = "systemProperties";

	String SYSTEM_ENVIRONMENT_BEAN_NAME = "systemEnvironment";

	//设置上下文ID
	void setId(String id);

	//设置父ApplicationContext
	void setParent(ApplicationContext parent);

	@Override
	ConfigurableEnvironment getEnvironment();
	
	void setEnvironment(ConfigurableEnvironment environment);

	
	void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor);

	//添加监听器
	void addApplicationListener(ApplicationListener<?> listener);

	//在子类中实现创建容器
	void refresh() throws BeansException, IllegalStateException;

	void registerShutdownHook();

	
	@Override
	void close();

	
	boolean isActive();

	//获取Bean工厂
	ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;

}



Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐