SpringCloud之EurekaServer

注意:spingcloud的版本号与springboot的冲突问题我这里用的springcloud版本是:finchley.SR2,springboot版本是:2.0.7。

Eureka是Netflix的开源的一个产品,主要用于服务注册和发现。

我们用尤里卡作为服务注册和发现中心。

下面开始我们的实战吧

项目的创建

我们使用IDEA来创建,因为IDEA太强大了。

首先新建工程:

注意不是选择maven方式

然后next

next后我们要选择我们的版本号和需要用到到包

 最后点击完成生成项目

编写配置文件

在application.yml文件中添加以下配置

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

在启动类添加注解
@EnableEurekaServer

package com.example.eurekademo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekademoApplication {

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

这样一个eureka服务项目就编写完成了

下面我们来测试下

测试

如下地址:http://127.0.0.1:8761/

启动成功可以看到如下界面

猜你喜欢

转载自blog.csdn.net/weixin_42545256/article/details/84869846