Read file from resources folder in Spring Boot

After spending a lot of time trying to resolve this issue, finally found a solution that works. The solution makes use of Spring’s ResourceUtils.
Should work for json files as well.

Thanks for the well written page by Lokesh Gupta : Blog

enter image description here

package utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;

import java.util.Properties;

public class Utils {

    private static final Logger LOGGER = LoggerFactory.getLogger(Utils.class.getName());

    public static Properties fetchProperties(){
        Properties properties = new Properties();
        try {
            File file = ResourceUtils.getFile("");
            InputStream in = new FileInputStream(file);
        } catch (IOException e) {
        return properties;

To answer a few concerns on the comments :

Pretty sure I had this running on Amazon EC2 using java -jar target/image-service-slave-1.0-SNAPSHOT.jar

Look at my github repo :
to figure out the right way to run this from a JAR.

Leave a Comment