From d4dedfa414741e0d58f16939071e5d14b31bee98 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 21 Nov 2020 14:26:44 +0100 Subject: [PATCH] Simplified the lookup of the required configuration-property --- .../MultipleBeansEnvironmentPostProcessor.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) 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(",")) -- 2.20.1