display application version in title using thymeleaf and springboot
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Displaying the application version in a Thymeleaf page is useful for support, QA, and deployment verification. In Spring Boot, the cleanest way to do it is to expose build metadata as a bean and pass that value into the model rather than hardcoding version strings in templates.
The Most Reliable Spring Boot Approach
Spring Boot can generate build metadata and expose it through the BuildProperties bean. That is usually better than manually maintaining a version string in a controller because the value comes from the actual build.
If you use Maven, enable the build-info goal in the Spring Boot plugin:
During the build, Spring Boot generates META-INF/build-info.properties. At runtime, Boot can turn that file into a BuildProperties bean.
Injecting the Version into a Controller
Once the build metadata exists, inject BuildProperties and add the version to the model.
Then use the value in Thymeleaf:
That updates the page title on every build without extra manual steps.
Making the Version Available to Every Template
If several pages need the version, do not repeat the same model.addAttribute call in every controller method. A @ControllerAdvice class can expose a shared model attribute globally.
Now every Thymeleaf template can use ${appVersion} without controller duplication.
Simpler Alternative: Read a Property
If you do not want build metadata, another option is to define the version in application.properties and inject it with @Value.
With Maven resource filtering enabled, @project.version@ is replaced during the build. Then inject it:
This works, but BuildProperties is more explicit and more aligned with Spring Boot's build metadata support.
Showing the Version Outside the Title
Once the version is in the model, you can reuse it anywhere in the page:
This is especially useful for QA builds or internal tools where support staff need to confirm the deployed artifact quickly.
Common Pitfalls
The first pitfall is hardcoding the version in the Thymeleaf template. That guarantees drift because someone eventually forgets to update it during a release.
Another pitfall is assuming Spring Boot creates BuildProperties automatically without build configuration. The bean appears only when the metadata file is generated.
A third pitfall is exposing the version in only one controller when several templates need it. A global model attribute is cleaner in that situation.
Finally, think about whether the exact version should be visible publicly. For internal tools it is usually helpful. For internet-facing applications, some teams prefer a less specific release label for security or product reasons.
Summary
- The clean Spring Boot solution is to generate build metadata and inject
BuildProperties - Add the version to the Thymeleaf model and render it in the title with
th:text - Use
@ControllerAdvicewhen multiple templates need the same version value - A filtered
application.propertiesvalue is a workable alternative - Avoid hardcoded template versions because they quickly drift from the real build
Related reading
- Display the current time and date in an Android application
- Distribute subscribers across JVMs
- Distribute using EJBs or replicate?
- Distributed Cache Jar in classpath but getting ClassNotFoundException
- Distributed Java Application with RestFul
- Distributed search system JAVA
- DistributedCache - third party jar not found
- Distributing events across different JVMs with Axon Server to Subscribing Event Processors (without Event Sourcing)

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.