簡體   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