![](/img/trans.png)
[英]2: No such directory error when running jar from bat file using scheduler
[英]No such file or directory - When running a service on JAR file
我正在构建一个 Spring Boot 应用程序。 我需要调用外部文件以从我的项目中使用其服务。
这是根目录的样子,
我需要在我的服务中读取红框中的文件,这是我的示例代码,
@Value("${2c2p.payment-action-api.encrypt-key-file.path:cert/demo/demo2.crt}")
private String encryptKeyFilePath;
@Value("${2c2p.payment-action-api.decrypt-key-file.path:cert/demo/demo2.pfx}")
private String decryptKeyFilePath;
我在我的开发函数中调用encryptKeyFilePath或decryptKeyFilePath (通过mvn spring-boot:run 运行)一切正常。
但是当我构建 JAR 文件时,看不到这些文件。
我是否需要在application.properties上添加一些配置或将cert 文件夹放在其他地方?
调用文件时的代码,
private String encrypt(String message) throws CertificateException, IOException {
String base64Str = pk.encryptMessage(message, pk.getPublicCert(encryptKeyFilePath));
return base64Str;
}
请帮忙。 非常感谢。
您可以使用ClassPathResource
,查看文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.