on-internet
← Community

Load json file from resource

Stack Overflow ·

I have a problem with loading a JSON file from a resource file. Here is my code: public void setConfiguration() { try { ClassLoader cl = this.getClass().getClassLoader(); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl); Resource[] resources = resolver.getResources("classpath*:/configuration.json"); if (resources.length == 0) { log.warn("Configuration could not be loaded from file! Using " + "default configuration."); configuration = getDefaultConfiguration(); } for (Resource resource : resources) { configuration = new ObjectMapper().readValue( resource.getInputSt

Comments

Sign in or sign up to comment and upvote.

No comments yet.