How do you build a microservice with Spring Boot and Spring Cloud?
Topic: microservices, Java Side. Level: Intermediate.
Answer
Spring Boot gives you an embedded server, auto-configuration, and Actuator (health/metrics) so each service is an independently deployable JAR. **Spring Cloud** adds the distributed-systems glue: config server (externalized config), discovery client (Eureka/Consul), declarative HTTP clients (OpenFeign), client-side load balancing, gateway, and Resilience4j integration. A typical service: expose REST controllers, register with discovery, read config centrally, and protect outbound calls with circuit breakers.
```java
@SpringBootApplication
@EnableDiscoveryClient // register with Eureka/Consul
public class OrderServiceApp {
public static void main(String[] a) { SpringApplication.run(OrderServiceApp.class, a); }
}
// build.gradle: spring-boot-starter-web, -actuator,
// spring-cloud-starter-netflix-eureka-client, -openfeign, resilience4j-spring-boot3
```