Simplified the lookup of the required configuration-property master
authorKai Moritz <kai@juplo.de>
Sat, 21 Nov 2020 13:26:44 +0000 (14:26 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 21 Nov 2020 14:24:53 +0000 (15:24 +0100)
src/main/java/de/juplo/demos/multiplebeans/MultipleBeansEnvironmentPostProcessor.java

index 0e31555..c4bb464 100644 (file)
@@ -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(","))