Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application version does not show up in Spring Boot banner.txt

The application version defined in the banner.txt does not show up on console, when running the application. It is defined according to the docs of Spring Boot

${application.version} 

The project uses the spring-boot-starter-parent as parent pom (Basic project setup from start.spring.io)

like image 833
pas2al Avatar asked Dec 29 '15 21:12

pas2al


People also ask

How do I get the app version in spring boot?

There are a few ways to get your application version with Spring Boot. One approach is using Maven resource filtering to add the version number as an enviroment variable in the application. yml during the build. Another approach is to use the Implementation-Version stored in the manifest file.

How do I change the text banner in spring boot?

Spring Boot accepts ASCII text, PNG, GIF, and JPG files as a custom startup banner. To configure an ASCII banner, all you need to do is just create a new ASCII banner using an online tool like Banner Generator and save it in src/main/resources/banner. txt file.


1 Answers

Ok, the version gets printed if i build the project and run it via java -jar. But if i start the application within my IDE (IntelliJ IDEA) the version will not be printed.

According to the Spring Boot documentation on Customizing the Banner, the value of ${application.version} is taken from the jar manifest.

The version number of your application as declared in MANIFEST.MF. For example Implementation-Version: 1.0 is printed as 1.0.

When running from an IDE, it's typical for execution to occur against the class files compiled by the IDE. The IDE typically doesn't go through a full cycle of building the whole jar with a manifest. Therefore, there is no MANIFEST.MF available at runtime for substituting the value of ${application.version}, and you're left with the bare token.

This is not a bug in your code, and you've already seen that it works correctly when doing a full jar build. If it's really important to fix this while running through the IDE, then you could consider setting up a custom build step that does go through the full jar build and manifest generation first. That's probably overkill though. The banner could be validated later outside the IDE by testing against a real release build of the jar.

like image 51
Chris Nauroth Avatar answered Sep 23 '22 00:09

Chris Nauroth