Spring IoC资源管理之ResourceLoader

简介: Spring IoC资源管理之ResourceLoader

概述


在上一章节Spring IoC资源管理之Resource提到 Spring 将资源的定义和资源的加载区分开了,Resource 定义了统一的资源,那资源的加载则由  ResourceLoader 来统一定义。


ResourceLoader


org.springframework.core.io.ResourceLoader 为 Spring 资源加载的统一抽象,具体的资源加载则由相应的实现类来完成,所以我们可以将 ResourceLoader 称作为统一资源定位器。其定义如下:


public interface ResourceLoader {
    String CLASSPATH_URL_PREFIX = "classpath:";
    Resource getResource(String var1);
    @Nullable
    ClassLoader getClassLoader();
}
复制代码


作为 Spring 统一的资源加载器,它提供了统一的抽象,具体的实现则由相应的子类来负责实现,其类的类结构图如下:


image.png


ResourceLoader 接口提供两个方法:getResource()getClassLoader()

getResource() 根据所提供的路径 location 返回 Resource 实例,但是它不确保该 Resource 一定存在,需要调用 Resource.exist() 方法判断。该方法支持以下模式的资源加载:

  • URL位置资源,如“file:D:/conf.xml”
  • ClassPath位置资源,如“classpath:conf.xml”
  • 相对路径资源,如"conf/conf.xml",此时返回的 Resource 实例根据实现不同而不同

该方法的主要实现是在其子类 DefaultResourceLoader 中实现,具体过程我们在分析 DefaultResourceLoader 时做详细说明。

getClassLoader() 返回 ClassLoader 实例,对于想要获取 ResourceLoader 使用的 ClassLoader 用户来说,可以直接调用该方法来获取。


DefaultResourceLoader


DefaultResourceLoader 是 ResourceLoader 的默认实现,它接收 ClassLoader 作为构造函数的参数或者使用不带参数的构造函数,在使用不带参数的构造函数时,使用的 ClassLoader 为默认的 ClassLoader(一般为Thread.currentThread().getContextClassLoader()),可以 通过 ClassUtils.getDefaultClassLoader()获取。当然也可以调用 setClassLoader()方法进行后续设置。如下:


public DefaultResourceLoader() {
    this.classLoader = ClassUtils.getDefaultClassLoader();
}
public DefaultResourceLoader(@Nullable ClassLoader classLoader) {
    this.classLoader = classLoader;
}
public void setClassLoader(@Nullable ClassLoader classLoader) {
    this.classLoader = classLoader;
}
@Nullable
public ClassLoader getClassLoader() {
    return this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader();
}
复制代码


ResourceLoader 中最核心的方法为 getResource(),它根据提供的 location 返回相应的 Resource,而 DefaultResourceLoader 对该方法提供了核心实现(它的两个子类都没有提供覆盖该方法,所以可以断定ResourceLoader 的资源加载策略就封装 DefaultResourceLoader中),如下:


public Resource getResource(String location) {
    Assert.notNull(location, "Location must not be null");
    Iterator var2 = this.getProtocolResolvers().iterator();
    Resource resource;
    do {
        if (!var2.hasNext()) {
            if (location.startsWith("/")) {
                return this.getResourceByPath(location);
            }
            if (location.startsWith("classpath:")) {
                return new ClassPathResource(location.substring("classpath:".length()), this.getClassLoader());
            }
            try {
                URL url = new URL(location);
                return (Resource)(ResourceUtils.isFileURL(url) ? new FileUrlResource(url) : new UrlResource(url));
            } catch (MalformedURLException var5) {
                return this.getResourceByPath(location);
            }
        }
        ProtocolResolver protocolResolver = (ProtocolResolver)var2.next();
        resource = protocolResolver.resolve(location, this);
    } while(resource == null);
    return resource;
}
复制代码


在分析该方法,我们需要认识一下 ProtocolResolver,该类与 DefaultResourceLoader 密不可分。ProtocolResolver 翻译过来叫做"协议解析器", 允许用户自定义协议资源解决策略,作为 DefaultResourceLoader 的 SPI,它允许用户自定义资源加载协议,而不需要继承 ResourceLoader 的子类。 在这个接口类中只有一个方法:


public interface ProtocolResolver {
    @Nullable
    Resource resolve(String var1, ResourceLoader var2);
}
复制代码


这个方法就是根据传入的 location 字符串,解析出对应的 Resource 资源。

在介绍 Resource 时,提到如果要实现自定义 Resource,我们只需要继承  AbstractResource 即可,但是有了 ProtocolResolver 后,我们不需要直接继承 DefaultResourceLoader,改为实现 ProtocolResolver 接口也可以实现自定义的 ResourceLoader。  


然后我们再来查看 getResource() 方法,首先通过 getProtocolResolvers()获取 ProtocolResolver 的集合,如果存在 ProtocolResolver,则直接用它来加载资源,并返回 Resource,否则调用如下逻辑:


  • 若 location 以/开头,则调用 getResourceByPath()构造 ClassPathContextResource  类型资源并返回;
  • 若 location 以 classpath:开头, 则构造 ClassPathResource 类型资源并返回,在构造该资源时,通过 getClassLoader()获取当前的 ClassLoader;
  • 构造 URL,尝试通过它进行资源定位,若没有抛出 MalformedURLException 异常,然后判断是否为 FileURL,如果是则构造 FileUrlResource 类型资源,否则构造 UrlResource。若在加载过程中抛出 MalformedURLException 异常,则 委派 getResourceByPath() 实现资源定位加载。


接下来看一个测试案例,代码如下:


@Test
public void useResourceLoader(){
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = null;
    String location = "";
    //location以/开头
    location = "/application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
    //location以classpath开头
    location = "classpath:application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
    //抛出MalformedURLException异常,进而执行getResourceByPath方法
    location = "target/classes/application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
    //同上
    location = "F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
    //ResourceUtils.isFileURL(url)为true,返回FileUrlResource
    location = "file:/target/classes/application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
    //ResourceUtils.isFileURL(url)为false,返回UrlResource
    location = "https://cn.bing.com/";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
}
复制代码


执行结果为:


class org.springframework.core.io.DefaultResourceLoader$ClassPathContextResource
class org.springframework.core.io.ClassPathResource
class org.springframework.core.io.DefaultResourceLoader$ClassPathContextResource
class org.springframework.core.io.DefaultResourceLoader$ClassPathContextResource
class org.springframework.core.io.FileUrlResource
class org.springframework.core.io.UrlResource
复制代码


FileSystemResourceLoader



在上一章节中,我们还提到了 FileSystemResource 类型,但是 DefaultResourceLoader 中并没有对此类型的处理,包括 getResourceByPath(String) 方法只是构建 ClassPathResource 类型。所以我们可以使用 FileSystemResourceLoader, 它继承 DefaultResourceLoader 且覆写了 getResourceByPath(String),使之从文件系统加载资源并以 FileSystemResource 类型返回,这样我们就可以得到想要的资源类型,如下:

protected Resource getResourceByPath(String path) {
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    return new FileSystemResourceLoader.FileSystemContextResource(path);
}
复制代码


FileSystemContextResource 为 FileSystemResourceLoader 的内部类,它继承 FileSystemResource。


private static class FileSystemContextResource extends FileSystemResource implements ContextResource {
    public FileSystemContextResource(String path) {
        super(path);
    }
    public String getPathWithinContext() {
        return this.getPath();
    }
}
复制代码


在构造器中也是调用 FileSystemResource 的构造方法来构造 FileSystemContextResource 的。


除了对getResourceByPath(String)方法的重写之外,其他方法都是复用 DefaultResourceLoader 中的方法。此时将上面的示例稍作修改:


@Test
public void useResourceLoader(){
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = null;
    String location = "";
    resourceLoader = new FileSystemResourceLoader();
    //抛出MalformedURLException异常,进而执行getResourceByPath方法
    location = "target/classes/application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
    //同上
    location = "F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/application_context.xml";
    resource = resourceLoader.getResource(location);
    System.out.println(resource.getClass());
}
复制代码


执行结果为:


class org.springframework.core.io.FileSystemResourceLoader$FileSystemContextResource
class org.springframework.core.io.FileSystemResourceLoader$FileSystemContextResource
复制代码


ResourcePatternResolver


ResourceLoader 的 Resource getResource(String location) 每次根据 location 返回一个 Resource,当需要加载多个资源时,必须要多次调用 getResource()方法,这样很不合理,所以引申而来了 ResourcePatternResolver。该类是 ResourceLoader 的扩展,它支持根据指定的资源路径匹配模式每次返回多个 Resource 实例,其定义如下:


public interface ResourcePatternResolver extends ResourceLoader {
    String CLASSPATH_ALL_URL_PREFIX = "classpath*:";
    Resource[] getResources(String var1) throws IOException;
}
复制代码


ResourcePatternResolver 在 ResourceLoader 的基础上增加了 getResources(String locationPattern),以支持根据路径匹配模式返回多个 Resource 实例,同时也新增了一种新的协议前缀 classpath*:,该协议前缀由其子类负责实现。


PathMatchingResourcePatternResolver 为 ResourcePatternResolver 最常用的子类(在后续构建应用上下文调试的过程中,会发现该类的使用),它除了支持 ResourceLoader 和 ResourcePatternResolver 新增的 classpath*: 前缀外,还支持 Ant 风格的路径匹配模式(类似于 **/*.xml)。


PathMatchingResourcePatternResolver 提供了三个构造方法,如下:


public PathMatchingResourcePatternResolver() {
    this.resourceLoader = new DefaultResourceLoader();
}
public PathMatchingResourcePatternResolver(ResourceLoader resourceLoader) {
    Assert.notNull(resourceLoader, "ResourceLoader must not be null");
    this.resourceLoader = resourceLoader;
}
public PathMatchingResourcePatternResolver(@Nullable ClassLoader classLoader) {
    this.resourceLoader = new DefaultResourceLoader(classLoader);
}
复制代码


PathMatchingResourcePatternResolver 在实例化的时候,可以指定一个 ResourceLoader,如果不指定的话,它会在内部构造一个 DefaultResourceLoader。


getResource()


该方法在当前类中的定义如下:


public Resource getResource(String location) {
    return this.getResourceLoader().getResource(location);
}
复制代码


getResource() 方法直接委托给相应的 ResourceLoader 来实现,所以如果我们在实例化 PathMatchingResourcePatternResolver 的时候,如果不知道 ResourceLoader ,那么在加载资源时,其实就是 DefaultResourceLoader 的过程。


getResources()

查看该方法的定义:


public Resource[] getResources(String locationPattern) throws IOException {
    Assert.notNull(locationPattern, "Location pattern must not be null");
    if (locationPattern.startsWith("classpath*:")) {
        return this.getPathMatcher().isPattern(locationPattern.substring("classpath*:".length())) ? this.findPathMatchingResources(locationPattern) : this.findAllClassPathResources(locationPattern.substring("classpath*:".length()));
    } else {
        int prefixEnd = locationPattern.startsWith("war:") ? locationPattern.indexOf("*/") + 1 : locationPattern.indexOf(58) + 1;
        return this.getPathMatcher().isPattern(locationPattern.substring(prefixEnd)) ? this.findPathMatchingResources(locationPattern) : new Resource[]{this.getResourceLoader().getResource(locationPattern)};
    }
}
复制代码


处理逻辑作图如下:


image.png

下面就 findAllClassPathResources()做详细分析。


findAllClassPathResources

当 locationPattern 以 classpath*: 开头但是不包含通配符,则调用findAllClassPathResources() 方法加载资源。 该方法返回 classes 路径下和所有 jar 包中的相匹配的资源。


protected Resource[] findAllClassPathResources(String location) throws IOException {
    String path = location;
    if (location.startsWith("/")) {
        path = location.substring(1);
    }
    Set<Resource> result = this.doFindAllClassPathResources(path);
    if (logger.isTraceEnabled()) {
        logger.trace("Resolved classpath location [" + location + "] to resources " + result);
    }
    return (Resource[])result.toArray(new Resource[0]);
}
复制代码


真正执行加载的是在 doFindAllClassPathResources()方法,如下:


protected Set<Resource> doFindAllClassPathResources(String path) throws IOException {
    Set<Resource> result = new LinkedHashSet(16);
    ClassLoader cl = this.getClassLoader();
    Enumeration resourceUrls = cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path);
    while(resourceUrls.hasMoreElements()) {
        URL url = (URL)resourceUrls.nextElement();
        result.add(this.convertClassLoaderURL(url));
    }
    if ("".equals(path)) {
        this.addAllClassLoaderJarRoots(cl, result);
    }
    return result;
}
复制代码


doFindAllClassPathResources() 根据 ClassLoader 加载路径下的所有资源。 如果在构造 PathMatchingResourcePatternResolver 实例时未传入 resourceLoader 或 classLoader 参数,则默认调用 DefaultResourceLoader 的 classLoader(默认为Thread.currentThread().getContextClassLoader())。然后调用 classLoader 的 getResources()方法,只有当 getClassLoader()返回为 null 时才会 调用ClassLoader.getSystemResources(path)ClassLoader.getResources()如下:


public Enumeration<URL> getResources(String var1) throws IOException {
    Enumeration[] var2 = (Enumeration[])(new Enumeration[2]);
    if (this.parent != null) {
        var2[0] = this.parent.getResources(var1);
    } else {
        var2[0] = getBootstrapResources(var1);
    }
    var2[1] = this.findResources(var1);
    return new CompoundEnumeration(var2);
}
复制代码


如果当前父类加载器不为 null,则通过父类向上迭代获取资源,否则调用 getBootstrapResources()。 这一部分得到的返回结果倒是可以看懂,但是在执行 resourceUrls.nextElement()语句时,对于如何得到的 url 的值不明白,如图所示:


image.png


如果有大神知悉,可否指点一下。


若 path 为 空(“”)时,则调用 addAllClassLoaderJarRoots()方法。该方法主要是加载路径下得所有 jar 包,方法较长也没有什么实际意义就不贴出来了。

通过上面的分析,我们知道 findAllClassPathResources() 其实就是利用 ClassLoader 来加载指定路径下的资源,不管它是在 class 路径下还是在 jar 包中。如果我们传入的路径为空或者 /,则会调用 addAllClassLoaderJarRoots() 方法加载所有的 jar 包。


findPathMatchingResources

当 locationPattern 以 classpath*: 开头且当中包含了通配符,则调用该方法进行资源加载。如下:


protected Resource[] findPathMatchingResources(String locationPattern) throws IOException {
    //获取根路径
    String rootDirPath = this.determineRootDir(locationPattern);
    String subPattern = locationPattern.substring(rootDirPath.length());
    //在根路径下扫描到的jar包或class路径
    Resource[] rootDirResources = this.getResources(rootDirPath);
    Set<Resource> result = new LinkedHashSet(16);
    Resource[] var6 = rootDirResources;
    int var7 = rootDirResources.length;
    for(int var8 = 0; var8 < var7; ++var8) {
        Resource rootDirResource = var6[var8];
        Resource rootDirResource = this.resolveRootDirResource(rootDirResource);
        URL rootDirUrl = ((Resource)rootDirResource).getURL();
        // bundle 资源类型
        if (equinoxResolveMethod != null && rootDirUrl.getProtocol().startsWith("bundle")) {
            URL resolvedUrl = (URL)ReflectionUtils.invokeMethod(equinoxResolveMethod, (Object)null, new Object[]{rootDirUrl});
            if (resolvedUrl != null) {
                rootDirUrl = resolvedUrl;
            }
            rootDirResource = new UrlResource(rootDirUrl);
        }
        // VFS 资源
        if (rootDirUrl.getProtocol().startsWith("vfs")) {
            result.addAll(PathMatchingResourcePatternResolver.VfsResourceMatchingDelegate.findMatchingResources(rootDirUrl, subPattern, this.getPathMatcher()));
        } else if (!ResourceUtils.isJarURL(rootDirUrl) && !this.isJarResource((Resource)rootDirResource)) {
            result.addAll(this.doFindPathMatchingFileResources((Resource)rootDirResource, subPattern));
        } else {
            result.addAll(this.doFindPathMatchingJarResources((Resource)rootDirResource, rootDirUrl, subPattern));
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Resolved location pattern [" + locationPattern + "] to resources " + result);
    }
    return (Resource[])result.toArray(new Resource[0]);
}
复制代码


方法有点儿长,但是思路还是很清晰的,主要分两步:

  1. 确定目录,获取该目录下得所有资源
  2. 在所获得的所有资源中进行迭代匹配获取我们想要的资源。

在这个方法里面我们要关注两个方法,一个是 determineRootDir(),一个是 doFindPathMatchingFileResources()


determineRootDir()主要是用于确定根路径,如下:


protected String determineRootDir(String location) {
    int prefixEnd = location.indexOf(58) + 1;
    int rootDirEnd;
    for(rootDirEnd = location.length(); rootDirEnd > prefixEnd && this.getPathMatcher().isPattern(location.substring(prefixEnd, rootDirEnd)); rootDirEnd = location.lastIndexOf(47, rootDirEnd - 2) + 1) {
    }
    if (rootDirEnd == 0) {
        rootDirEnd = prefixEnd;
    }
    return location.substring(0, rootDirEnd);
}
复制代码


该方法一定要给出一个确定的根目录。该根目录用于确定文件的匹配的起始点,将根目录位置的资源解析为 java.io.File 并将其传递到 retrieveMatchingFiles(),其余为知用于模式匹配,找出我们所需要的资源。


确定根路径如下:


原路径 根路径
classpath:test/cc/spring-*.xml classpath*:test/
classpath:test/aa/spring-.xml classpath*:test/aa/
file:F:/workspace/test/target/classes/*/beans.xml file:F:/workspace/test/target/classes/


确定根路径后,则调用 getResources() 方法获取该路径下得所有资源,然后迭代资源获取符合条件的资源。


下面给出一个案例,代码如下:


@Test
public void usePatternResolver() throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = null;
    String location = "";
    //使用DefaultResourceLoader的情况下,改变location的内容
    location = "application_context.xml";
    resources = resolver.getResources(location);//调用DefaultResourceLoader.getResource()方法
    sout(resources);
    location = "classpath*:config/beans.xml";
    resources = resolver.getResources(location);//findAllClassPathResources
    sout(resources);
    location = "classpath*:*/beans.xml";
    resources = resolver.getResources(location);//findPathMatchingResources
    sout(resources);
    location = "file:F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/*/beans.xml";
    resources = resolver.getResources(location);//findPathMatchingResources
    sout(resources);
    location = "F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/application_context.xml";
    resources = resolver.getResources(location);//调用resourceLoader.getResource()方法
    sout(resources);
    //更新ClassLoader
    location = "F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/application_context.xml";
    resolver = new PathMatchingResourcePatternResolver(new FileSystemResourceLoader());
    resources = resolver.getResources(location);//调用FileSystemResourceLoader.getResource()方法
    sout(resources);
}
public void sout(Resource[] resources){
    for(Resource resource:resources){
        System.out.println(resource);
    }
}
复制代码


执行结果为:


class path resource [application_context.xml]
URL [file:/F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/config/beans.xml]
file [F:\workspace\Spmvc_Learn\spring_study\spring-chap1\target\classes\config\beans.xml]
file [F:\workspace\Spmvc_Learn\spring_study\spring-chap1\target\classes\config\beans.xml]
class path resource [F:/workspace/Spmvc_Learn/spring_study/spring-chap1/target/classes/application_context.xml]
file [F:\workspace\Spmvc_Learn\spring_study\spring-chap1\target\classes\application_context.xml]
复制代码


总结


经过两章节的讲述,关于 Spring 资源管理的过程已经分析完毕。下面简要总结下:

  • Spring 提供了 Resource 和 ResourceLoader 来统一抽象整个资源及其定位。使得资源与资源的定位有了一个更加清晰的界限,并且提供了合适的 Default 类,使得自定义实现更加方便和清晰。


  • AbstractResource 为 Resource 的默认实现类,它对 Resource 接口做了统一的实现,子类继承该类后只需要覆盖相应的方法即可,同时对于自定义的 Resource 我们也是继承该类。


  • DefaultResourceLoader 同样也是 ResourceLoader 的默认实现,在自定义 ResourceLoader 的时候我们除了可以继承该类外还可以实现 ProtocolResolver 接口来实现自定义资源加载协议。


  • DefaultResourceLoader 每次只能返回单一的资源,所以 Spring 针对该情况提供了另一个接口 ResourcePatternResolver,该接口提供了根据指定的 locationPattern 返回多个资源的策略。其子类 PathMatchingResourcePatternResolver 是一个集大成者的 ResourceLoader,因为它既实现 了 Resource getResource(String location) 也实现了 Resource[] getResources(String locationPattern)



目录
相关文章
|
XML Java 测试技术
Spring IOC—基于注解配置和管理Bean 万字详解(通俗易懂)
Spring 第三节 IOC——基于注解配置和管理Bean 万字详解!
1095 26
|
10月前
|
XML Java 测试技术
《深入理解Spring》:IoC容器核心原理与实战
Spring IoC通过控制反转与依赖注入实现对象间的解耦,由容器统一管理Bean的生命周期与依赖关系。支持XML、注解和Java配置三种方式,结合作用域、条件化配置与循环依赖处理等机制,提升应用的可维护性与可测试性,是现代Java开发的核心基石。
|
XML 人工智能 Java
Spring IOC 到底是什么?
IOC(控制反转)是一种设计思想,主要用于解耦代码,简化依赖管理。其核心是将对象的创建和管理交给容器处理,而非由程序直接硬编码实现。通过IOC,开发者无需手动new对象,而是由框架负责实例化、装配和管理依赖对象。常见应用如Spring框架中的BeanFactory和ApplicationContext,它们实现了依赖注入和动态管理功能,提升了代码的灵活性与可维护性。
328 1
|
XML Java 数据格式
Spring IoC容器的设计与实现
Spring 是一个功能强大且模块化的 Java 开发框架,其核心架构围绕 IoC 容器、AOP、数据访问与集成、Web 层支持等展开。其中,`BeanFactory` 和 `ApplicationContext` 是 Spring 容器的核心组件,分别定位为基础容器和高级容器,前者提供轻量级的 Bean 管理,后者扩展了事件发布、国际化等功能。
436 18
|
XML Java 数据格式
【SpringFramework】Spring IoC-基于XML的实现
本文主要讲解SpringFramework中IoC和DI相关概念,及基于XML的实现方式。
408 69
|
XML Java 数据格式
京东一面:spring ioc容器本质是什么? ioc容器启动的步骤有哪些?
京东一面:spring ioc容器本质是什么? ioc容器启动的步骤有哪些?
|
Java 容器 Spring
什么是Spring IOC 和DI ?
IOC : 控制翻转 , 它把传统上由程序代码直接操控的对象的调用权交给容 器,通过容器来实现对象组件的装配和管理。所谓的“控制反转”概念就是对组件对象控制权的转 移,从程序代码本身转移到了外部容器。 DI : 依赖注入,在我们创建对象的过程中,把对象依赖的属性注入到我们的类中。
|
设计模式 XML Java
【23种设计模式·全精解析 | 自定义Spring框架篇】Spring核心源码分析+自定义Spring的IOC功能,依赖注入功能
本文详细介绍了Spring框架的核心功能,并通过手写自定义Spring框架的方式,深入理解了Spring的IOC(控制反转)和DI(依赖注入)功能,并且学会实际运用设计模式到真实开发中。
【23种设计模式·全精解析 | 自定义Spring框架篇】Spring核心源码分析+自定义Spring的IOC功能,依赖注入功能
|
Java Spring 容器
【SpringFramework】Spring IoC-基于注解的实现
本文主要记录基于Spring注解实现IoC容器和DI相关知识。
352 21
|
存储 Java 应用服务中间件
【Spring】IoC和DI,控制反转,Bean对象的获取方式
IoC,DI,控制反转容器,Bean的基本常识,类注解@Controller,获取Bean对象的常用三种方式
673 12

热门文章

最新文章