classpath*:
时间: 2023-07-24 13:15:32 浏览: 48
classpath*: 是一个 Spring Framework 所特有的类路径匹配符号,它可以用在 XML 配置文件中的 <import>、<context:component-scan> 等标签的 location 属性值中,用于匹配多个 jar 包中的同名文件。其中,* 号可以匹配任意字符,包括目录分隔符。这个符号可以方便地将一个项目分成多个 jar 包进行管理,并且在运行时仍然可以通过 classpath 扫描到所有的配置文件和类。
相关问题
mapper-locations: classpath*:/**/*.xml
mapper-locations: classpath*:/**/*.xml 是一个配置项,用于告诉Spring Boot或MyBatis在类路径下递归搜索所有满足指定路径模式(/**/*.xml)的XML文件作为Mapper文件。
这个配置项中的"classpath*:"表示在所有的类路径下搜索,而不仅仅是当前应用程序的类路径。而"/**/*.xml"表示递归搜索所有以.xml结尾的文件。
这样配置可以方便地将Mapper文件放置在不同的目录下,而不需要手动指定每个目录的路径。Spring Boot或MyBatis会自动搜索并加载这些Mapper文件,使其可用于数据库操作。
范例:
```xml
<!-- application.properties -->
mybatis.mapper-locations=classpath*:/mapper/**/*.xml
```
上述配置将会在所有的类路径下递归搜索mapper目录下的所有.xml文件作为Mapper文件。
配置文件classpath:和classpath*:的区别
在Java中,classpath和classpath*都是用来指定类加载器在哪些路径中查找类或资源文件的。
- classpath: 表示只在指定的路径中查找类或资源文件,不包括子目录。例如classpath:/config/application.properties只会在config目录下查找application.properties文件,而不会在其子目录中查找。
- classpath*: 表示在指定的路径及其子目录中查找类或资源文件。例如classpath*:/config/application.properties会在config目录及其子目录中查找application.properties文件。
因此,通常情况下我们使用classpath*,这样可以方便地查找包含在子目录中的类或资源文件。但是在某些情况下,如果我们确定类或资源文件只在指定的路径下,可以使用classpath:来指定。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)