本文主要是介绍Spring之ClassPathXmlApplicationContext,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Spring 官方文档
-
Spring Framework Documentation【Version 5.1.4.RELEASE】
-
ClassPathXmlApplicationContext API Doc
源码
package org.springframework.context.support;import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext {private Resource[] configResources;public ClassPathXmlApplicationContext() {}public ClassPathXmlApplicationContext(ApplicationContext parent) {super(parent);}public ClassPathXmlApplicationContext(String configLocation) throws BeansException {this(new String[] {configLocation}, true, null);}// JDK5可变参数(Varargs)public ClassPathXmlApplicationContext(String... configLocations) throws BeansException {this(configLocations, true, null);}public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {this(configLocations, true, parent);}public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException {this(configLocations, refresh, null);}public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)throws BeansException {super(parent);// 传入String数组configLocationssetConfigLocations(configLocations);if (refresh) {refresh();}}public ClassPathXmlApplicationContext(String path, Class<?> clazz) throws BeansException {this(new String[] {path}, clazz);}public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz) throws BeansException {this(paths, clazz, null);}public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, ApplicationContext parent)throws BeansException {super(parent);Assert.notNull(paths, "Path array must not be null");Assert.notNull(clazz, "Class argument must not be null");this.configResources = new Resource[paths.length];for (int i = 0; i < paths.length; i++) {this.configResources[i] = new ClassPathResource(paths[i], clazz);}refresh();}@Overrideprotected Resource[] getConfigResources() {return this.configResources;}}
这篇关于Spring之ClassPathXmlApplicationContext的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!