aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/preprocess/SpringPropertiesFacade.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess/SpringPropertiesFacade.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/SpringPropertiesFacade.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/SpringPropertiesFacade.java b/src/main/java/at/gv/egiz/moazs/preprocess/SpringPropertiesFacade.java
new file mode 100644
index 0000000..4cce7e0
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/preprocess/SpringPropertiesFacade.java
@@ -0,0 +1,39 @@
+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<String> 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);
+ }
+}