Laden Sie die JSON -Datei aus der Ressource

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Laden Sie die JSON -Datei aus der Ressource

by Anonymous » 25 Feb 2025, 22:02

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?

Top