summaryrefslogtreecommitdiff
path: root/eaaf-springboot-utils/src/main/java/at
diff options
context:
space:
mode:
authorThomas <>2021-06-18 08:18:59 +0200
committerThomas <>2021-06-18 08:18:59 +0200
commit108df5e1cc640070d1b03fb2dfd99306e661b8fe (patch)
tree3480ccccbf20011572f2dc3b3db743d9f12d1482 /eaaf-springboot-utils/src/main/java/at
parent5a2544a18d44eec63ace935b1869da9c67d73f6c (diff)
downloadEAAF-Components-108df5e1cc640070d1b03fb2dfd99306e661b8fe.tar.gz
EAAF-Components-108df5e1cc640070d1b03fb2dfd99306e661b8fe.tar.bz2
EAAF-Components-108df5e1cc640070d1b03fb2dfd99306e661b8fe.zip
update some log messages
Diffstat (limited to 'eaaf-springboot-utils/src/main/java/at')
-rw-r--r--eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/utils/VersionHolder.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/utils/VersionHolder.java b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/utils/VersionHolder.java
new file mode 100644
index 00000000..9d996853
--- /dev/null
+++ b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/utils/VersionHolder.java
@@ -0,0 +1,42 @@
+package at.gv.egiz.eaaf.utils.springboot.utils;
+
+import java.util.Optional;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
+
+/**
+ * SpringBoot based implementation of an application-version holder.
+ *
+ * @author tlenz
+ *
+ */
+@Service
+public class VersionHolder {
+
+ private final String version;
+
+ /**
+ * Holder that extracts the current version of the SpringBoot application.
+ *
+ * @param context Spring ApplicationContext
+ */
+ public VersionHolder(ApplicationContext context) {
+ version = context.getBeansWithAnnotation(SpringBootApplication.class).entrySet().stream()
+ .findFirst()
+ .flatMap(es -> Optional.ofNullable(es.getValue().getClass().getPackage().getImplementationVersion()))
+ .orElse("unknown");
+
+ }
+
+ /**
+ * Get version of this application.
+ *
+ * @return version
+ */
+ public String getVersion() {
+ return version;
+
+ }
+}