In my SpringBoot application I have to read a Json file at this path src/main/resources/mock/fileName.json. I done it in this way
JsonReader jsonReaderStream = new JsonReader(new InputStreamReader(Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResourceAsStream("./mock/fileName.json"))));
It works locally but when I deploy my docker file on Kubernetes and I try to read my Json file I received a NullPointerException. I use gradle for the build. I state that I am a beginner on gradle, docker and kubernetes.
Can anyone explain to me why it works locally but not on Kubernetes ?
There are two possibilities here.
Go into the
.jar
package, and check if yourmock/x.json
exists intarget\example.jar!\BOOT-INF\classes
.If it is being packaged but not found, see this answer.
new ClassPathResource("./mock/fileName.json")
and then useresource.getInputStream()
.I strongly recommend you to place these static json files under
resources/static/
, so you can directly have these files such asresources/static/mock/a.json
, as being requested as/mock/a.json