From 108df5e1cc640070d1b03fb2dfd99306e661b8fe Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Fri, 18 Jun 2021 08:18:59 +0200 Subject: update some log messages --- .../eaaf/utils/springboot/utils/VersionHolder.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/utils/VersionHolder.java (limited to 'eaaf-springboot-utils/src/main/java/at') 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; + + } +} -- cgit v1.2.3