gpt4 book ai didi

spring-boot - 在 spring application.properties 文件中的资源文件夹中指定文件

转载 作者:行者123 更新时间:2023-12-03 14:37:09 25 4
gpt4 key购买 nike

我有一个 Spring Boot 应用程序,代码需要访问资源文件夹下的文件。这是我的 application.properties 文件:

cert.file=classpath:/resources/cert.p12

然而它总是提示:
java.io.FileNotFoundException: classpath:/resources/cert.p12 (No such file or directory)

我仔细检查了文件夹
my_project/目标/类
确保文件 cert.p12 存在于那里。

在我尝试访问该文件的代码中:
@Value("${cert.file}")
private String certFile;
....
@Bean
public Sender sender() {
return new Sender(certFile);
}

这个类路径到底是什么?为什么它找不到文件?谢谢!

最佳答案

类路径包括您所拥有的 你的资源目录。

尝试:

cert.file=classpath:cert.p12

我假设您有标准的 Maven 目录结构。

关于spring-boot - 在 spring application.properties 文件中的资源文件夹中指定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32278204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com