SpringCloud学习(一)之Eureka搭建

2020-04-04  本文已影响0人  程序员小杰

一、添加依赖

image.png
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

这里使用的boot版本为2.2.2.RELEASE,cloud版本为Hoxton.SR1。
需要注意一下版本

image.png
官网地址:https://spring.io/projects/spring-cloud#overview

在启动类上加上注解@EnableEurekaServer,表明该项目是Eureka Server

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

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

}

然后修改yml文件

spring:
  application:
    name: eureka  #服务名
server:
  port: 1998  #eureka 默认端口为8761
eureka:
  client:
    register-with-eureka: false  #是否注册到eureka上  默认为true  但是我这个是作为Eureka Server的,所以不需要注册
    fetch-registry: false  #是否从Eureka Server上获取注册信息

访问:http://localhost:1998/

image.png
上一篇 下一篇

猜你喜欢

热点阅读