Eureka搭建注册中心-简版
1.pom.xml依赖添加
<!-- Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureka-server</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<!-- Spring Cloud -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2.配置文件
spring:
application:
name: eureka-server
server:
port: 8761
eureka:
client:
fetch-registry: false #由于注册中心的职责就是维护服务实例,它并不需要去检索服务,所以也设置为false
register-with-eureka: false #由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己
eureka.client.register-with-eureka一定要配置为false,不然启动时会把自己当作客户端向自己注册,会报错。
3.创建启动类
@SpringBootApplication
@EnableEurekaServer //表示开启Eureka Server
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}