zoukankan      html  css  js  c++  java
  • Spring中 classpath* 和 classpath 前缀的区别

    1     // org.springframework.core.io.support.ResourcePatternResolver
    2     /**
    3      * Pseudo URL prefix for all matching resources from the class path: "classpath*:"
    4      * This differs from ResourceLoader's classpath URL prefix in that it
    5      * retrieves all matching resources for a given name (e.g. "/beans.xml"),
    6      * for example in the root of all deployed JAR files.
    7      * @see org.springframework.core.io.ResourceLoader#CLASSPATH_URL_PREFIX
    8      */
    9     String CLASSPATH_ALL_URL_PREFIX = "classpath*:";
        // org.springframework.core.io.ResourceLoader
        /** Pseudo URL prefix for loading from the class path: "classpath:" */
        String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX;

    说明:写了另一篇文章,想详细了解的可以过去看看。

    Spring Framework 官方文档学习(三)之Resource


    简单的说,如果有多个文件时,classpath* 前缀再加上通配符,会搜到所有符合的文件;而classpath前缀再加上通配符则可能会在找到一个符合的之后不再查找。

    所以使用classpath* 总是没错的。

    顺便提一句,这个前缀是在ApplicationContext的实现类的构造方法中处理的,用于甄别资源(Resource)类型。

    稍后会写一下Resource类型与ApplicationContext类型的关系,以及有无前缀的区别。

    详见官方文档

  • 相关阅读:
    git分支合并
    php错误处理
    php面试全套
    php面试的那些“黑话”
    快速在命令窗口打开当前路径
    @Autowired注解的使用方法
    jsp页面获取表单的值
    jsp打印九九乘法表
    Google hack
    java中的集合collection
  • 原文地址:https://www.cnblogs.com/larryzeal/p/5915324.html
Copyright © 2011-2022 走看看