IOC资源管理

AbstractXmlApplicationContext 中组合了一个 XmlBeanDefinitionReader 组件来解析 xml 配置文件
资源模型:

原生java加载资源方式:
借助 ClassLoader 加载类路径下的资源
借助 File 加载文件系统中的资源
借助 URL 和不同的协议加载本地 / 网络上的资源

DefaultResourceLoader组合了一堆ProtocolResolver:

private final Set<ProtocolResolver> protocolResolvers = new LinkedHashSet<>(4);

public Resource getResource(String location) {
    Assert.notNull(location, "Location must not be null");

    for (ProtocolResolver protocolResolver : getProtocolResolvers()) {
        Resource resource = protocolResolver.resolve(location, this);
        if (resource != null) {
            return resource;
        }
    }
    // ......
}

@FunctionalInterface
public interface ProtocolResolver {
	Resource resolve(String location, ResourceLoader resourceLoader);
}
posted @ 2022-10-04 21:58  无极是一种信仰  阅读(22)  评论(0编辑  收藏  举报