zoukankan      html  css  js  c++  java
  • spring中classpath和classpath*的配置区别

    spring中classpath和classpath*的配置区别

     

    在使用spring时,经常会看到类似 classpth:、classpath*: 这样的前缀,不管是加载spring xml配置文件还是其配置文件中加载资源文件都会看到这两种前缀配置,其实这两种前缀是有区别的,下面将举例详细解释。

    spring配置文件:applicationContext.xml 中两种不同的properties文件加载配置:

    第一种:classpath:

    <context:property-placeholder ignore-unresolvable="true"
        location="classpath:/application.properties" />

    这种配置下运行测试代码,日志信息中有关加载properties资源文件只有一条 如下:

    Loading properties file from class path resource [application.properties]

    第二种: classpath*:

    <context:property-placeholder ignore-unresolvable="true"
        location="classpath*:/application.properties" />

    这种配置下运行测试代码,日志信息中有关加载properties资源文件会有三条如下:

     Loading properties file from URL [file:/D:/workspace_sun/framework-dev/micmiu-demoweb/target/test-classes/application.properties]
     Loading properties file from URL [file:/D:/workspace_sun/framework-dev/micmiu-demoweb/target/classes/application.properties]
     Loading properties file from URL [jar:file:/D:/micmiu-test.jar!/application.properties]

    由此日志信息可知:

    • 同名资源存在时,classpath: 只从第一个符合条件的classpath中加载资源,而classpath*: 会从所有的classpath中加载符合条件的资源
    • classpath*:需要遍历所有的classpath,效率肯定比不上classpath,因此在项目设计的初期就尽量规划好资源文件所在的路径,避免使用classpath*来加载
  • 相关阅读:
    C语言输出颜色
    嵌入式Linux串口编程简介
    推荐:实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求
    嵌入式串口打印信息重定向到当前终端界面
    C、C++、boost、Qt在嵌入式系统开发中的使用
    LInux下Posix的传统线程示例
    Linux用C语言模拟‘ls‘命令
    关于Linux目录访问函数总结
    Inter内部指令--AVX编程基础
    SPECCPU2006测试(456测试小记)
  • 原文地址:https://www.cnblogs.com/cheng07045406/p/3726151.html
Copyright © 2011-2022 走看看