I am using Spring boot 2.0.4, trying read a json file which is placed in resources/ directory, but getting the 'FileNotFoundException'.
I have referred a lot of pages from Stackoverflow, and other links, but no success so far.
Following is the stack trace snippet, I am not sure why there is '!' in the classpath:
/opt/springboot/myProject.jar!/BOOT-INF/classes!/schema/jsonValidationSchema.json at o.s.u.ResourceUtils.getFile(ResourceUtils.java:217) at o.s.u.ResourceUtils.getFile(ResourceUtils.java:180)
This is the code snippet:
InputStream in = new ClassPathResource("jsonValidationSchema.json").getInputStream();
JsonNode schemaJsonNode = JsonLoader.fromReader(new InputStreamReader(in, "UTF-8"));
JsonSchema schemaNode = ValidationUtils.getSchemaNode(schemaJsonNode);
References:
File inside jar is not visible for spring
Read file from resources folder in Spring Boot
https://smarterco.de/java-load-file-from-classpath-in-spring-boot/
java.io.FileNotFoundException: class path resource cannot be opened because it does not exist