![](/img/trans.png)
[英]In Eclipse, Junit is not picking up files from src/test/resources folder.
[英]Wildfly is not picking up the files under the resources folder
我正在做一個 spring boot 項目,在這個項目中我會隨每個請求發送一個客戶端證書。 我已將客戶端證書放在resources/keystore/certificate.jks文件夾中。 但是,當我在 wildfly 中部署應用程序時,出現以下錯誤
java.io.FileNotFoundException: class path resource [keystore/certificate.jks] cannot be resolved to absolute file path because it does not reside in the file system: vfs:/content/ProjectName.war/WEB-INF/classes/keystore/certificate.jks
我正在以下列方式讀取文件
public RestTemplate getTemplate(RestTemplateBuilder builder) throws Exception{
char[] password = "changeit".toCharArray();
final SSLContext sslContext = SSLContextBuilder.create()
.loadKeyMaterial(keyStore("classpath:keystore/certificate.jks", password,"KeyStore"), password)
.build();
HttpClient client = HttpClients.custom().setSSLContext(sslContext).build();
return builder
.requestFactory(new HttpComponentsClientHttpRequestFactory(client))
.build();
}
private KeyStore keyStore(String file, char[] password,String type) throws Exception {
KeyStore keyStore = KeyStore.getInstance("JKS");
File key = ResourceUtils.getFile(file);
try (InputStream in = new FileInputStream(key)) {
keyStore.load(in, password);
}catch(Exception e) {
e.printStackTrace();
}
return keyStore;
}
當我將此應用程序作為 Spring Boot 應用程序運行時,它運行成功,但是當我打包此應用程序並將其部署在 Wildfly 服務器中時,它給了我 FileNotFoundError
雖然我不明白以這種方式發送證書的意圖。 在wildfly 理解事物的上下文中,它是通過模塊。 您可以創建自定義模塊並在 WildFly 中加載它們。 你可以參考: https : //kb.novaordis.com/index.php/Writing_a_Custom_WildFly_Module
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.