Récupérer la version avec spring boot
Le plus simple c'est de lire le fichier version.properties dans le classpath.
1try(InputStream inputStream = getClass().getClassLoader().getResourceAsStream("version.properties")){
2 Properties prop = new Properties();
3 prop.load(inputStream);
4 String version=prop.get("version","1.0.0");
5 return version;
6}
Il existe d'autres façons de faire :
Autres solutions:
- [https://stackoverflow.com/questions/3697449/retrieve-version-from-maven-pom-xml-in-code]
- [https://www.baeldung.com/spring-boot-build-properties]