I have a service (Spring Boot). One of my features is to read a docx file, replace some text and save on the clients computer.
I have a file skom.docx and locally I can without any problems find that file:
@Getter
public enum ReportTemplatesEnum {
KANC("src/main/resources/templates/skom.docx");
private final String path;
}
(...)
File file = new File(reportData.getReportType().getPath()); --> the path from Enum
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument doc = new XWPFDocument(fis);
(...)
But when I deploy my service to the server (containerized in Docker) I get the error: Request: /odo/incident/generateOneReport/255 methodGET
java.io.FileNotFoundException: /src/main/resources/templates/skom.docx (No such file or directory)
How to prepare the path to my files? Locally works perfectly.
UPDATE - SOLUTION
Resource resource = new ClassPathResource(reportData.getReportType().getPath());
InputStream dbAsStream = resource.getInputStream();
XWPFDocument doc = new XWPFDocument(dbAsStream);