Springboot获得pom中版本信息

运行时期望获得的jar包版本信息

pom.xml

<groupId>com.xxx.yyy</groupId>
<artifactId>xxxxxxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xxxxxx</name>
<description>yyyyyyy</description>

代码获取

场景描述:
下面的代码是独立的功能组件Jar包, 向外提供@EnableXXXX的注解. 在初始化时, 从使用@EnableXXXX的Springboot应用中获取其相关的版本信息.

Map<String, Object> mapper = SpringContext.getApplicationContext().getBeansWithAnnotation(xxxx.class);
Optional<Package> annotationPkg = Optional.ofNullable(mapper.values().toArray()[0].getClass().getPackage());
String implementationTitile = annotationPkg.get().getImplementationTitle();
String implementationVersion = annotationPkg.get().getImplementationVersion();

猜你喜欢

转载自blog.csdn.net/rosemary512/article/details/118926630