分为三个步骤:resource文件定位、加载、注册。IOC容器其实就是一个map,concurrentHashMap
加载过程中,默认会读取xml文件中前缀是classpath的文件路径。呈上代码:
StringCLASSPATH_ALL_URL_PREFIX ="classpath*:";
public Resource[] getResources(String locationPattern)throws IOException {
Assert.notNull(locationPattern,"Location pattern must not be null");
if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
// a class path resource (multiple resources for same name possible)
if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
// a class path resource pattern
return findPathMatchingResources(locationPattern);
}
else {
// all class path resources with the given name
return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
}
}
网友评论