package at.gv.egiz.moazs.preprocess; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.stream.Stream; import java.util.stream.StreamSupport; @Component public class SpringPropertiesFacade { @Autowired private ConfigurableEnvironment env; /** * Collect all properties from Spring environment and return them as a stream. * * inspired by https://stackoverflow.com/questions/23506471/spring-access-all-environment-properties-as-a-map-or-properties-object/42521523#42521523 * @author pedorro * @return */ public Stream getPropertyNames() { MutablePropertySources propSrcs = env.getPropertySources(); return StreamSupport.stream(propSrcs.spliterator(), false) .filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()) .flatMap(Arrays::stream); } public String getProperty(String name) { return env.getProperty(name); } }