当类路径包含许多目录时,类路径根是什么意思?
What is meant by the classpath root when the classpath contains many directories?
The spring boot documentation 表示它在类路径根目录中查找 application.properties。我试图弄清楚我的类路径根是什么,但是当我打印类路径时,它包含许多用冒号分隔的目录。
我收集到所有这些目录都被搜索以加载 类.
这是否意味着它们中的任何一个文件都将被视为位于类路径根目录中?如果其中两个目录中存在同名文件怎么办?
在您的情况下,实际上有多个 class 路径根。 class路径的每个组成部分都是一个class路径根。例如,如果您有 classpath of:
/user/home/dir1:/user/home/dir2
dir1 和 dir2 都是 class路径根,您可以将 application.properties 放在任何一个地方,Spring Boot 会找到它。
这里spring的意思是它有一些默认的location/s,它将根据优先级寻找resource/s。
根据 Spring docs,优先级如下所示:
file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/
The spring boot documentation 表示它在类路径根目录中查找 application.properties。我试图弄清楚我的类路径根是什么,但是当我打印类路径时,它包含许多用冒号分隔的目录。 我收集到所有这些目录都被搜索以加载 类.
这是否意味着它们中的任何一个文件都将被视为位于类路径根目录中?如果其中两个目录中存在同名文件怎么办?
在您的情况下,实际上有多个 class 路径根。 class路径的每个组成部分都是一个class路径根。例如,如果您有 classpath of:
/user/home/dir1:/user/home/dir2
dir1 和 dir2 都是 class路径根,您可以将 application.properties 放在任何一个地方,Spring Boot 会找到它。
这里spring的意思是它有一些默认的location/s,它将根据优先级寻找resource/s。
根据 Spring docs,优先级如下所示:
file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/