Spring Boot microservices guide

Getting started with Spring Boot microservices

Spring Middleware helps you build Spring Boot microservices by adding a platform layer for service discovery, communication, and infrastructure consistency. Start with a minimal setup, register your service, and progressively enable platform capabilities such as declarative clients, messaging, and GraphQL.

Spring Boot microservices tutorial Service discovery setup Declarative communication Service registration Incremental platform adoption

What you need to start

A typical service imports the platform modules it needs, keeps business logic in its own modules, and enables platform capabilities through regular Spring Boot configuration.

  • Import dependency management or the required module versions
  • Add only the runtime modules the service actually needs
  • Keep a normal Spring Boot entry point
  • Register resources and configure the Registry endpoint

Adoption model

Spring Middleware is modular. You do not need to adopt everything on day one. Start with the smallest useful set of modules and keep the service architecture explicit.

  • Recommended approach: import the BOM and add only the runtime modules you need.
  • Lightweight approach: add individual modules with explicit versions for smaller integrations.
  • Main goal: keep versions aligned and avoid per-service dependency drift.

Minimal service structure

Spring Middleware fits naturally into a modular service layout. Business logic stays in your own codebase, while the platform layer handles infrastructure concerns consistently.

Typical module layout

*-api — shared contracts and DTOs
*-core — business logic
*-boot — Spring Boot runtime module

Runtime integration

The *-boot module usually depends on Spring Middleware platform modules such as app, messaging modules, GraphQL support, or data integrations depending on the service role.

  • Keep shared DTOs and interfaces separate from runtime wiring
  • Keep business logic in your own core module
  • Use the Boot module as the integration point for platform capabilities

Startup flow

The initial integration is straightforward: add the right modules, keep a normal Spring Boot application, register your resources, and configure the control plane endpoint.

01

Add platform dependencies

Import dependency management and add the Spring Middleware modules required by your service.

02

Keep a standard Boot application

A regular @SpringBootApplication remains the service entry point.

03

Register resources and clients

Expose controllers with @Register and use @MiddlewareClient for remote contracts.

04

Configure the Registry

Point the service to the control plane and enable the platform capabilities relevant to the runtime.

Availability

Available on Maven Central

Available on Maven Central and ready to use in any Spring Boot application.

Coordinates

io.github.spring-middleware:orchestrator-core:1.0.0
io.github.spring-middleware:orchestrator-infra:1.0.0

Dependency management

In most cases, the cleanest entry point is version alignment through dependency management, followed by adding only the modules the service actually uses.

Managed versions

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>${spring.boot.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>

    <dependency>
      <groupId>io.github.spring-middleware</groupId>
      <artifactId>app</artifactId>
      <version>${spring-middleware.app.version}</version>
    </dependency>

    <dependency>
      <groupId>io.github.spring-middleware</groupId>
      <artifactId>api</artifactId>
      <version>${spring-middleware.api.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

Runtime modules

<dependencies>
  <dependency>
    <groupId>io.github.spring-middleware</groupId>
    <artifactId>app</artifactId>
  </dependency>

  <dependency>
    <groupId>io.github.spring-middleware</groupId>
    <artifactId>kafka-core</artifactId>
  </dependency>
</dependencies>

Practical rule

Do not import everything. The platform is modular. Start with the small set of modules your service needs, but keep versions aligned through the BOM whenever possible.

Application entry point

Spring Middleware does not require a special application model. A standard Boot application remains the runtime entry point.

@SpringBootApplication
public class CatalogApplication {

    public static void main(String[] args) {
        SpringApplication.run(CatalogApplication.class, args);
    }
}

Declarative clients and registration

Cross-service communication and topology registration are both explicit. Services declare remote contracts and register their own resources in the control plane.

Declarative client

@MiddlewareClient(service = "product")
public interface ProductClient {

    @GetMapping("/products/{id}")
    ProductDto getProduct(@PathVariable("id") UUID id);
}

Registered controller

@RestController
@Register
@RequestMapping("/catalogs")
public class CatalogController {
    // endpoints
}

See also the client security guide for outbound authentication with declarative clients.

Registry-driven resolution Explicit contracts Consistent error propagation Trace context propagation

Minimal configuration

Most services start with registry configuration, client security, and only the infrastructure sections that are relevant to their runtime behavior.

Registry

spring:
  middleware:
    registry:
      url: ${REGISTRY_ENDPOINT:http://localhost:8080/registry}
      enabled: true

Client configuration

middleware:
  client:
    registry-endpoint: ${REGISTRY_ENDPOINT:http://localhost:8080/registry}
    product:
      security:
        type: OAUTH2_CLIENT_CREDENTIALS
        api-key: ${API_KEY_PRODUCT_SERVICE:default-product-api-key}
        oauth2:
          client-id: ${OAUTH2_CLIENT_ID_PRODUCT_SERVICE:product-service}
          client-secret: ${OAUTH2_CLIENT_SECRET_PRODUCT_SERVICE}
          token-uri: ${OAUTH2_TOKEN_URI_PRODUCT_SERVICE:http://keycloak:8080/realms/spring-middleware/protocol/openid-connect/token}

Kafka

kafka:
  bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
  create-missing-topics: true
  topics:
    catalog-events:
      partitions: 5
      replication-factor: 3

Logging trigger

middleware:
  log:
    apiKey: ${MIDDLEWARE_LOG_API_KEY:}

Reference service example

See a concrete multi-module example with a root aggregator, a minimal catalog-service, realistic runtime configuration, and a declarative client calling another service.

What the example includes

  • Root aggregator pom.xml
  • Minimal catalog-service module
  • Spring Boot main class
  • Realistic application.yml
  • Declarative client usage with ProductApi

Open the reference example

A complete Spring Boot microservices example showing how a real Spring Middleware service is structured, configured, and connected to the platform.

Security, build, and local execution

The platform supports service-level and client-level security, but the basic local workflow remains familiar: package the Boot module and run the jar or start it from the IDE.

Practical notes

A few details usually matter early: version alignment, local topic creation, Docker build context, and configuration binding in tests.

Common early checks

  • Use the BOM to keep module versions aligned across services
  • Enable topic auto-creation locally, but manage topics explicitly in production
  • Check .dockerignore if Docker builds cannot see the generated jar
  • Make sure required configuration properties can bind in tests

What this page is for

This page is intentionally narrow. It helps a service cross the initial integration line. Deeper runtime behavior belongs in the architecture, registry, communication, messaging, GraphQL, security, and error model pages.