Spring Boot 2.0 adds Eureka

Eureka Server

Spring cloud has helped me implement a service registry, and we only need a few simple steps to complete it.

1. Adding dependencies to pom will

spring-cloud-starter-eureka-server 换成 spring-cloud-starter-netflix-eureka-client
<dependencies>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>

2. Add @EnableEurekaServerannotations to the startup code

@SpringBootApplication
@EnableEurekaServer
public class SpringCloudEurekaApplication {

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

3. Configuration file

By default, the service registry will also try to register itself as a client, so we need to disable its client registration behavior by application.ymladding the following configuration:

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Fourth, start the project
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324807208&siteId=291194637