Spring Cloud Netflix Documentation
repository·main·Indexed 26 days ago
https://github.com/spring-cloud/spring-cloud-netflixProvides Netflix OSS integrations for Spring Boot applications, specifically focusing on service discovery and load balancing. It enables the creation of embedded Eureka servers and the integration of Eureka Clients for service registration and discovery. The documentation covers configuration via application properties, TLS authentication, health checks, and the management of Spring Cloud LoadBalancer retry behavior and metrics.
What's inside Spring Cloud Netflix
- Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot applications. It uses Spring Boot autoconfiguration and binds to the Spring Environment and other Spring programming model idioms. This allows developers to quickly enable and configure common distributed system patterns, such as Service Discovery via Eureka, using simple annotations to build large-scale distributed systems with battle-tested Netflix components.
Overview of Spring Cloud Netflix features
mainSpring Cloud Netflix provides capabilities for service discovery within a Spring ecosystem. Key features include:
- Service Discovery (Client): Eureka instances can be registered and clients can discover instances using Spring-managed beans.
- Service Discovery (Server): An embedded Eureka server can be created using declarative Java configuration.
Features of Spring Cloud Netflix
mainSpring Cloud Netflix provides the following core capabilities:
- Service Discovery: Eureka instances can be registered and clients can discover instances using Spring-managed beans.
- Embedded Eureka Server: An embedded Eureka server can be created using declarative Java configuration.
Set up an embedded Eureka Server
mainTo run your own Eureka discovery server, add the
spring-cloud-starter-netflix-eureka-serverdependency to your project and annotate your main configuration class with@EnableEurekaServer.@EnableEurekaServer @SpringBootApplication public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }Build the Netflix project module
mainTo build thespring-cloud-netflix-hystrix-contractmodule along with the entire Netflix project, use thebuild.shscript located in thescriptsdirectory.Configure a Eureka Client in a Spring Boot application
mainTo enable a Spring Boot application to act as a Eureka client (registering with a discovery server and discovering other services), add the
spring-cloud-starter-netflix-eureka-clientdependency to your project.By default, the client will attempt to contact a Eureka server at
http://localhost:8761. This default location is controlled by the configuration keyeureka.client.serviceUrl.defaultZone.@SpringBootApplication @RestController public class Application { @RequestMapping("/") public String home() { return "Hello World"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }Generate documentation using Antora
mainThe
spring-cloud-buildmodule includes adocsprofile that uses Antora to build documentation from AsciiDoc sources located inmodules/ROOT/.To generate the documentation site, run the following command:
./mvnw -pl docs -P docs antora:antoraInclude Eureka Client in your project
mainTo enable service discovery in your microservice, add the Eureka Client starter to your build system. This automatically registers your application as a Eureka "instance" and allows it to act as a "client" to query the registry.Configure Spring Cloud Netflix using application properties or command line switches
mainYou can configure Spring Cloud Netflix features by specifying properties in any of the following locations:
application.propertiesfileapplication.ymlfile- Command line switches
Note that this list of properties is not exhaustive, as additional JAR files on your classpath may contribute further properties, and you can also define custom properties.
Import project into Eclipse
mainYou can import the project into Eclipse using two different methods:
Using m2e plugin (Recommended)
Use the
m2eEclipse plugin for Maven support. If you encounter errors related to POMs, ensurem2eis up to date or manually add thespringprofile to yoursettings.xmlto resolve Spring repositories.Without m2e plugin
If you do not use
m2e, you can generate Eclipse-specific project metadata using theeclipse:eclipsegoal, then import the projects viaFile > Import > Existing Projects.$ ./mvnw eclipse:eclipseInclude Eureka Server in your project
mainTo create a Eureka Discovery Server, add the Eureka Server starter to your project and annotate your main application class with
@EnableEurekaServer.@SpringBootApplication @EnableEurekaServer public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }Secure the Eureka Server
mainTo secure the Eureka Server, add
spring-boot-starter-securityto your classpath. You must explicitly disable CSRF protection for the/eureka/**endpoints so that Eureka clients can still communicate with the server.@Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests((authz) -> authz .anyRequest().authenticated()) .httpBasic(withDefaults()); http.csrf().ignoringRequestMatchers("/eureka/**"); return http.build(); }