Laden Sie die JSON -Datei aus der RessourceJava

Java-Forum
Anonymous
 Laden Sie die JSON -Datei aus der Ressource

Post by Anonymous »

Ich habe ein Problem beim Laden von JSON -Datei aus der Ressource.
Hier ist mein Code: < /p>

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.getInputStream(), Configuration.class);
if (configuration != null) {
log.debug("Configuration found (using PathMatchingResourcePatternResolver)");
break;
}
}
} catch (Exception e) {
log.warn("Configuration could not be loaded from file! Using default configuration.", e);
configuration = getDefaultConfiguration();
}
}
< /code>

Es wird immer eine Standardkonfiguration benötigt. Weiß jemand, warum es keine Werte aus der JSON -Datei benötigt?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post