使用 file:// 前缀和不使用前缀有什么区别?

What is the difference between using the file:// prefix, and its absence?

我配置 Spring 云配置服务器。我的 application.yml 如下所示。

spring:
  cloud:
    config:
      server:
        git:
          uri: ${HOME}/Desktop/configs

我对 uri 参数感兴趣。文档中https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html写的是指定路径所以

spring.cloud.config.server.git.uri: file://${user.home}/config-repo

但是,在不指定 file:// 前缀的情况下(如我所用),一切正常。使用 file:// 前缀和不使用前缀有什么区别?

file:// 确定它将在文件系统上查找,因此您可以放置​​相对路径并在文件系统中导航。

classpath:// 确定它将查找您的 service/project 的类路径。当你想引用 resources 例如

时,使用这个更容易

默认类型是 file://,但我建议将它作为前缀,所以它在您查看的位置是明确的:)

更多信息见https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/resources.html