Eureka基于Netflix Eureka做了二次封装
一、两个组件
1.Eureka Server 注册中心
引入包:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
加注解:@EnableEurekaServer
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
配置yml文件
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
# register-with-eureka: false
# server:
# enable-self-preservation: false
spring:
application:
name: eureka
server:
port: 8761
2.Eureka Client 服务注册