DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Manage Microservices With Docker Compose
  • Configuring Java Apps With Kubernetes ConfigMaps and Helm
  • A New Era Of Spring Cloud
  • DGS GraphQL and Spring Boot

Trending

  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • How To Develop a Truly Performant Mobile Application in 2025: A Case for Android
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  1. DZone
  2. Software Design and Architecture
  3. Microservices
  4. Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin

Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin

Discover how to verify microservice deployments with the Spring Boot Build Info Maven Plugin, increasing the dependability of your deployment pipeline.

By 
Amol Gote user avatar
Amol Gote
DZone Core CORE ·
Aug. 07, 23 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
5.1K Views

Join the DZone community and get the full member experience.

Join For Free

In the case of microservices, we faced a unique challenge: when a container was deployed, there was no way for us to verify if the latest container build with the expected code had been deployed. It's easy to verify in cases where a new feature is being deployed and is testable in production. However, with fintech applications, we can't necessarily validate all-new production APIs. There are also instances where a bug fix is applied to an existing API, and you can't execute that API use case in production. There were times when the DevOps team informed us that the container had been lifted and deployed from a lower UAT environment, but we didn't see the bug fixes in action when real production traffic began. To circumvent this, we wanted to ensure that there was a way to validate the latest code when the container was pushed.

In our case, we were dealing with spring-based microservices. That's when the Spring Boot Maven plugin came to the rescue. It's necessary to add the build-info Maven plugin within the project's pom.xml file.

XML
 
<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <executions>
        <execution>
          <goals>
            <goal>
              build-info
            </goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>


After configuring the build info, when the project is built, you can view the build-info.properties file under the target/classes/META-INFO directory. It will look something like this:

Properties files
 
build.artifact=core-build-info-api
build.group=com.dzone
build.name=core-build-info-api
build.time=2023-07-29T15\:47\:25.387Z
build.version=1.0-SNAPSHOT


To access these properties at runtime, Spring provides the BuildProperties class, which exposes all the properties from the above file. Below is a code snippet for a generic service that constructs the build information for the deployed microservice:

Java
 
@Service
public class BuildInfoService {

    @Autowired
    BuildProperties buildProperties;

    @Autowired
    Environment environment;

    public BuildInfoResponse getBuildInfo(){
        BuildInfoResponse buildInfoResponse = new BuildInfoResponse();
        buildInfoResponse.setName(this.buildProperties.getName());
        buildInfoResponse.setVersion(this.buildProperties.getVersion());
        buildInfoResponse.setTime(this.buildProperties.getTime());
        buildInfoResponse.setActiveProfile(this.environment.getActiveProfiles());
        buildInfoResponse.setSpringVersion(this.buildProperties.getVersion());
        buildInfoResponse.setGroup(this.buildProperties.getGroup());
        buildInfoResponse.setArtifact(this.buildProperties.getArtifact());
        return buildInfoResponse;
    }
}


You can then inject this service and build a generic endpoint to expose the build information for the container. In our case, we built a common package known as core-build-info, which includes the aforementioned service and a common controller as below:

Java
 
@RestController
@RequestMapping("/${build-info.path}")
public class BuildInfoController {

    @Autowired
    BuildInfoService buildInfoService;

    @GetMapping("/build-info")
    public BuildInfoResponse getBuildInfo() {
        return this.buildInfoService.getBuildInfo();
    }
}


All the business or utility microservices refer to the common package and configure the following property in the Spring profile properties file:

Properties files
 
env=DEV
build-info.path=api/app-name/build


The app name could be your business base service route.

Once the common package has been integrated, you can hit the endpoint for your microservice using the following URL, which returns the following:

JSON
 
{
    "name": "core-build-info-api",
    "version": "0.0.1",
    "time": "2023-07-29T16:13:42.251Z",
    "artifact": "core-build-info-api",
    "group": "com.dzone",
    "activeProfile": [
        "DEV"
    ],
    "springVersion": "6.0.10"
}


If you have a version increment configured as part of your build, then you can verify the version. Alternatively, you can always fall back to checking the build time, which in this example is "2023-07-29T16:13:42.251Z".

In conclusion, dealing with microservices and ensuring the latest code deployment can present unique challenges. By leveraging the capabilities of the Spring Boot Maven plugin and creating a common package to expose build information, we have developed a reliable method to overcome this challenge. This process enables us to confirm that the correct version and build of the microservice has been deployed in production, providing confidence and assurance in our deployment pipeline. The real-world value of this approach is evident: it is now the first thing we verify upon deploying a container.

You can find the entire codebase on GitHub.

Apache Maven Use case Build (game engine) microservice Property (programming) Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • Manage Microservices With Docker Compose
  • Configuring Java Apps With Kubernetes ConfigMaps and Helm
  • A New Era Of Spring Cloud
  • DGS GraphQL and Spring Boot

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!