Accessing a Resource in a Spring Boot Application

I have a Spring Boot Web Application (Embedded Jetty Server). All java code and resources are packaged inside a JAR and deployed to the server. However, there is a JSON file outside of the JAR, but in the classpath. those.

my classpath: / usr / local / myserver /
JSON file is located at: /usr/local/myserver/hello.json The
JAR is located at: /usr/local/myserver/app.jar

When I find the url: https: // IP: port / hello.json it gives me "404 file not found". The IP address shown is the server where all files and JARs are present. I believe the default resource path is / static / .. which is inside the JAR. Any file in this static directory is available.

I configured:

public class StaticResourceConfiguration extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {

public void addResourceHandlers(ResourceHandlerRegistry registry) {


How can I access the JSON file?


source to share

2 answers

If the file is JSON

already in classpath

, then why don't you use a prefix classpath:




if you use a prefix file:/

then it loads JSON file

using the url class, so basically you need to give the absolute location of the path like

if these are windows





You need to use the "file: //" prefix + the absolute destination on your filesystem "/ usr / local / myserver /".





All Articles