繁体   English   中英

没有这样的文件或目录 - 在 JAR 文件上运行服务时

[英]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;

我在我的开发函数中调用encryptKeyFilePathdecryptKeyFilePath (通过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 ,查看文档:

https://www.baeldung.com/spring-classpath-file-access

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM