SpringBoot read Maven ProjectVersion

src/main/resources/application.properties中添加
version=@project.version@

Note the red part of the @ project.version @, rather than the $ {project.version} placeholder, mainly to avoid conflict with the Spring grammar

Once configured, you can directly obtain the notes by way of @Value

@Value("${version}")
private String version;

Properties can also load the code

final Properties properties = new Properties();    
properties.load(this.getClass().getClassLoader().getResourceAsStream("application.properties")); return properties.getProperty("version");

@Value comment recommend ways
https://stackoverflow.com/questions/26551439/getting-maven-project-version-and-artifact-id-from-pom-while-running-in-eclipse/26573884#26573884
HTTPS: // stackoverflow.com/questions/37490162/get-maven-properties-at-build-time#37490162

Guess you like

Origin www.cnblogs.com/a-du/p/12166358.html