Backend Development 8 min read

Essential Spring Boot Practices for Building Robust Microservices

This article outlines the golden rules for constructing Spring Boot microservices, covering monitoring with Spring Boot Admin and Grafana, exposing metrics via Actuator, centralized logging with ELK, clear API documentation using Swagger, YApi or smart‑doc, transparent build info, and keeping dependencies up‑to‑date.

macrozheng
macrozheng
macrozheng
Essential Spring Boot Practices for Building Robust Microservices

Introduction

In this article we share the "golden rules" for building Spring Boot microservice applications.

System Runs on a White Box

Monitoring and visualization systems such as Spring Boot Admin or Grafana can reveal most runtime issues, provide charts and alerts, and are especially important in microservice architectures.

Spring Boot Actuator can expose runtime metrics; adding the following dependency enables it:

<code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;
</code>

The metric

http.server.requests

is a key indicator, offering request count and response time statistics.

Common storage backends for Actuator metrics are InfluxDB and Prometheus; Prometheus pulls data from endpoints, while InfluxDB requires the application to push via REST API. In small projects, Spring Boot Admin (in‑memory) can be used.

Be sure to block external exposure in production environments.

Logging

Logging is often overlooked during development but becomes critical for operations; it should be a key review and testing criterion.

Use a consistent logging standard across microservices, record trace IDs with MDC, differentiate instances, and capture request execution times.

Centralized log storage is recommended; the Elastic Stack (ELK) is a popular choice.

<code><!-- integrate logstash -->
&lt;dependency&gt;
    &lt;groupId&gt;net.logstash.logback&lt;/groupId&gt;
    &lt;artifactId&gt;logstash-logback-encoder&lt;/artifactId&gt;
    &lt;version&gt;5.3&lt;/version&gt;
&lt;/dependency&gt;
</code>

For small projects or limited expertise, cloud provider log services (e.g., Qiniu LogKit, LogEasy) are inexpensive alternatives.

Ensuring Clear API Documentation

Microservice APIs require timely and accurate documentation.

Swagger is a well‑known tool for generating online API docs with minimal configuration.

For a more comprehensive DevOps workflow, YApi offers powerful API management, supporting Swagger import and real‑time maintenance.

Dubbo services can use smart‑doc, which generates documentation from annotations without code intrusion.

Application Information Transparency

Rapid delivery in microservice environments demands exposing version and change information for each release.

The Spring Boot Maven plugin can generate build info; accessing

/actuator/info

reveals details such as artifact, version, build time, and group.

<code>&lt;plugins&gt;
    &lt;plugin&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
        &lt;executions&gt;
            &lt;execution&gt;
                &lt;goals&gt;
                    &lt;goal&gt;build-info&lt;/goal&gt;
                &lt;/goals&gt;
            &lt;/execution&gt;
        &lt;/executions&gt;
    &lt;/plugin&gt;
&lt;/plugins&gt;
</code>

Visit

/actuator/info

to see build metadata.

SpringBootAdmin (with git‑commit‑id‑plugin) can list registered applications and display their version or commit information.

Timely Dependency Updates

Spring Boot and Spring Cloud release new versions monthly, bringing features and bug fixes; newer versions improve startup time and memory usage, making them well‑suited for containerization.

Example Maven parent and dependencyManagement configuration for the latest stable releases:

<code>&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.4.1&lt;/version&gt;
&lt;/parent&gt;
&lt;dependencyManagement&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
            &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
            &lt;version&gt;2020.0.0&lt;/version&gt;
            &lt;type&gt;pom&lt;/type&gt;
            &lt;scope&gt;import&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
</code>

Spring Cloud version details are illustrated below.

monitoringmicroservicesdependency managementLoggingSpring BootAPI Documentation
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.