three common tools used for Spring Boot
1. Spring Cloud
Spring Cloud provides tools for building common patterns in distributed systems, such as configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, global locks, leadership election, distributed sessions, and cluster state.
Table of Contents
```java
// Spring Cloud Config Server
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
```
Configuration:
```yaml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/example/config-repo
```
2. Netflix Eureka
Eureka is a REST-based service used for locating services for the purpose of load balancing and failover of middle-tier servers. It provides a way to locate services by the name they are registered with and communicate with them without hard coding their IP addresses.
```java
// Eureka Server
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
// Eureka Client
@SpringBootApplication
@EnableEurekaClient
@RestController
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
@GetMapping("/greeting")
public String greeting() {
return "Hello from Eureka Client!";
}
}
```
Configuration (for Eureka Server):
```yaml
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
```
Configuration (for Eureka Client):
```yaml
server:
port: 8080
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
```
3. Spring Boot Actuator
Spring Boot Actuator provides production-ready features to help you monitor and manage your application. It exposes various endpoints that can be used to monitor the application, gather metrics, understand traffic, or even change application configuration at runtime.
```java
@SpringBootApplication
public class ActuatorApplication {
public static void main(String[] args) {
SpringApplication.run(ActuatorApplication.class, args);
}
}
```
Configuration:
```yaml
management:
endpoints:
web:
exposure:
include: health, info, metrics
```