Eureka是Spring Cloud中的注册中心,类似Dubbo中的Zookeeper,
Eureka 是 Netflix 开发的,一个基于 REST 服务的,服务注册与发现的组件
- pom.xml
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
- 注册中心,启动类。
@SpringBootApplication
@EnableEurekaServer//开启EurekaServer功能
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
- 注册中心配置文件
#当前服务名称
spring.application.name=eureka
#设置端口
server.port=1111
#默认情况下,Eureka Server也是一个普通的微服务,所以当它是一个注册中心的时候,又两个身份(1.注册中心 2.普通服务)
#当前服务会默认吧自己注册进来 设置为false当前项目不要注册到注册中心
eureka.client.register-with-eureka=false
#是否从Eureka Server上获取注册信息
eureka.client.fetch-registry=false