classpath 和 classpath* 的区别
classpath 和 classpath* 的区别
classpath 和 classpath* 是两种不同的类路径搜索模式,它们在寻找资源文件时有所不同:
- classpath:
classpath表示只在当前类加载器的类路径中搜索资源,不包括依赖的 JAR 文件和其他类加载器的路径。这意味着只有当前项目或模块的类路径下的资源文件会被搜索到。 - classpath*:
classpath*表示在所有类加载器的类路径中搜索资源,包括当前项目的类路径和所有依赖的 JAR 文件中的类路径。这使得你可以在整个应用程序的类路径中搜索资源。
下面是一个示例,以更清晰地说明这两种类路径搜索模式的区别:
假设你有一个 Spring Boot 项目,项目结构如下:
my-project/
├── src/
│ ├── main/
│ │ ├── java/
│ │ ├── resources/
│ │ │ ├── application.properties
│ │ └── static/
│ │ │ ├── styles.css
└── lib/
├── my-library.jar
- 使用
classpath:
如果使用 classpath 来搜索资源,比如 classpath:application.properties,它将仅在当前项目的类路径中搜索。因此,只有 my-project 中的 resources 目录下的 application.properties 文件会被找到。
- 使用
classpath*:
如果使用 classpath* 来搜索资源,同样搜索 classpath:application.properties,它将搜索整个应用程序的类路径,包括 my-project 中的类路径以及 my-library.jar 中的类路径。因此,application.properties 文件会被搜索到,无论它位于哪个类路径中。
总结:classpath 只搜索当前项目的类路径,而 classpath* 搜索整个应用程序的类路径,包括依赖的 JAR 文件。你可以根据需要选择适当的类路径搜索模式。
classpath 和 classpath* 的区别的更多相关文章
- web.xml 配置中classpath: 与classpath*:的区别
首先 classpath是指 WEB-INF文件夹下的classes目录 解释classes含义: 1.存放各种资源配置文件 eg.init.properties log4j.properties s ...
- classpath: 和classpath*:的区别
classpath本质是jvm的根路径,jvm获取资源都是从该根路径下找的,注意这个根路径是个逻辑路径,并不是磁盘路径.比如两个jar包的路径是/a/a.jar和/b/b.jar,但是用classpa ...
- 在web.xml中classpath和classpath*的区别
classpath 和 classpath* 区别: classpath:只会到你指定的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar文件中(class路径) ...
- WEB项目web.xml文件中classpath: 跟classpath*:使用的区别
引用一篇很不错的文章:http://blog.csdn.net/wxwzy738/article/details/16983935 首先 classpath是指 WEB-INF文件夹下的classes ...
- 【转载】Spring加载resource时classpath*:与classpath:的区别
免责声明: 本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除. 原文作者:kyfxbl 原文地址: spring配置中classpath和cla ...
- web.xml中classpath:和classpath*: 有什么区别?
web.xml中classpath:和classpath*: IccBoY applicationContext.xml 配置文件的存放位置 web.xml中classpath:和classp ...
- Spring配置中的"classpath:"与"classpath*:"的区别研究(转)
Spring配置中的"classpath:"与"classpath*:"的区别研究(转) 概念解释及使用场景: classpath是指WEB-INF文件夹下 ...
- 转:web.xml 配置中classpath: 与classpath*:的区别
原文链接:web.xml 配置中classpath: 与classpath*:的区别 引用自:http://blog.csdn.net/wxwzy738/article/details/1698393 ...
- web.xml 配置中classpath: 与classpath*:的区别——(十一)
首先 classpath是指 WEB-INF文件夹下的classes目录 解释classes含义: 1.存放各种资源配置文件 eg.init.properties log4j.properties s ...
- Spring配置中的"classpath:"与"classpath*:"的区别研究
概念解释及使用场景: classpath是指WEB-INF文件夹下的classes目录. 通常我们一般使用这种写法实在web.xml中,比如spring加载bean的上下文时,如下: <!--系 ...
随机推荐
- 聊聊 RocketMQ 名字服务
NameServer 是专为 RocketMQ 设计的轻量级名字服务,它的源码非常精简,八个类 ,少于1000行代码. 这篇文章, 笔者会从基础概念.Broker发送心跳包.NameServer 维护 ...
- 第一个程序PingPong
功能需求 如图所示,开启两个ping类型的服务ping1和ping2,ping1给ping2发消息,ping2收到回应ping1,ping1收到再回应ping2,不断循环. 服务模块 Skynet提供 ...
- 【Hexo】插件推荐以及使用小技巧
目录 插件推荐 hexo-deployer-git hexo-word-counter hexo-abbrlink hexo-generator-sitemap 小技巧 自定义提交信息 参考资料 He ...
- Kafka入门学习
什么是 Kafka Kafka 是由 Linkedin 公司开发的,它是一个分布式的,支持多分区.多副本,基于 Zookeeper 的分布式消息流平台,它同时也是一款开源的基于发布订阅模式的消息引擎系 ...
- Codeforces 1257E - The Contest
题意 三个人,每个人有一些数字,组合起来是\(1\)-\(n\),每个人可以给另一个人一个拥有的数字,问最小操作数,使得第一个人拥有\(1\)-\(i\)的数,第二个人拥有\(i+1\)-\(j\)的 ...
- docker搭建dvwa靶场
查看有哪些DVWA镜像 docker search dvwa 这里选择拉取第一个镜像 docker pull citizenstig/dvwa 访问 https://hub.docker.com/ 搜 ...
- 五分钟k8s实战-使用Ingress
背景 前两章中我们将应用部署到了 k8s 中,同时不同的服务之间也可以通过 service 进行调用,现在还有一个步骤就是将我们的应用暴露到公网,并提供域名的访问. 这一步类似于我们以前配置 Ngin ...
- git命令和遇到的问题
命令 1.快速关联/修改Git远程仓库地址 (1).删除本地仓库当前关联的无效远程地址,再为本地仓库添加新的远程仓库地址 git remote -v //查看git对应的远程仓库地址 git remo ...
- E-GraphSAGE: A Graph Neural Network based Intrusion Detection System 笔记
E-GraphSAGE: A Graph Neural Network based Intrusion Detection System 目录 E-GraphSAGE: A Graph Neural ...
- 如何vue3中使用全局变量,与Vue2的区别
对比: 在vue2.x中我们挂载全局变量或方法是通过是使用Vue.prototype.$xxxx=xxx的形式来挂载,然后通过this.$xxx来获取挂载到全局的变量或者方法 但是 在vue3.x中显 ...