ฉันมีแอปพลิเคชัน Spring Boot รหัสจำเป็นต้องเข้าถึงไฟล์ภายใต้โฟลเดอร์ทรัพยากร นี่คือไฟล์ application.properties ของฉัน:
cert.file=classpath:/resources/cert.p12
แต่ก็บ่นอยู่เสมอว่า
java.io.FileNotFoundException: classpath:/resources/cert.p12 (No such file or directory)
ฉันตรวจสอบโฟลเดอร์ my_project/target/classes อีกครั้งเพื่อให้แน่ใจว่าไฟล์ cert.p12 ออกจากที่นั่น
และในโค้ดฉันพยายามเข้าถึงไฟล์:
@Value("${cert.file}")
private String certFile;
....
@Bean
public Sender sender() {
return new Sender(certFile);
}
classpath นี้คืออะไรกันแน่? แล้วทำไมมันหาไฟล์ไม่เจอล่ะ? ขอบคุณ!