From: Kai Moritz Date: Sat, 21 Nov 2020 13:26:44 +0000 (+0100) Subject: Simplified the lookup of the required configuration-property X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=demos%2Fmultiple-beans Simplified the lookup of the required configuration-property --- diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansEnvironmentPostProcessor.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansEnvironmentPostProcessor.java index 0e31555..c4bb464 100644 --- a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansEnvironmentPostProcessor.java +++ b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansEnvironmentPostProcessor.java @@ -3,7 +3,6 @@ package de.juplo.demos.multiplebeans; import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.PropertySource; import java.util.Arrays; @@ -11,15 +10,7 @@ public class MultipleBeansEnvironmentPostProcessor implements EnvironmentPostPro @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - String sites = null; - for (PropertySource source : environment.getPropertySources()) { - Object found = source.getProperty("juplo.sites"); - if (found != null) - sites = found.toString(); - } - - if (sites == null) - throw new IllegalArgumentException("Parameter juplo.sites is not set!"); + String sites = environment.getRequiredProperty("juplo.sites", String.class); application.addInitializers(new MultipleBeansApplicationContextInitializer( Arrays.stream(sites.split(","))