How to do the application versioning in the spring boot?

南楼画角 提交于 2019-12-24 06:34:13

问题


I am using spring boot and gradle for my application. The application can have different versions and we need to show this version info on the application in the footer.

e.g. 1.0.0 or 1.0.0.RELEASE etc

what are the possible ways to do this?


回答1:


There is a good example in the documentation. You can automatically expand properties from the Gradle project and refer those properties as placeholders in your application.properties file.

 processResources {
     expand(project.properties) 
 }

You can then refer to your Gradle project’s properties via placeholders, e.g.

app.name=${name} 
app.description=${description}

You are then able to use for example the @Value annotation to get the properties value in your application.

@Value("${app.version}")
public String appVersion;

@Override
public void run(String... arg0) throws Exception {
    System.out.println(appVersion);
}

Maybe you have to escape the placeholder mechanism:

Gradle’s expand method uses Groovy’s SimpleTemplateEngine which transforms ${..} tokens. The ${..} style conflicts with Spring’s own property placeholder mechanism. To use Spring property placeholders together with automatic expansion the Spring property placeholders need to be escaped like \${..}.

P.S.:With maven you can do the same. more...



来源:https://stackoverflow.com/questions/41951861/how-to-do-the-application-versioning-in-the-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!