站长网 资讯 Eureka单节点构建的高效处理

Eureka单节点构建的高效处理

在有的教程中,会引入 spring-boot-starter-web,这个依赖其实不用,因为 spring-cloud-starter-netflix-eureka-server的依赖已经包含了它,在pom依赖进去,就可以了 dependency groupIdorg.springframework.cloud/groupId artifactIdspring-cloud-starter

在有的教程中,会引入 spring-boot-starter-web,这个依赖其实不用,因为 spring-cloud-starter-netflix-eureka-server的依赖已经包含了它,在pom依赖进去,就可以了

<dependency> 

  <groupId>org.springframework.cloud</groupId> 

  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> 

</dependency> 

2.2 application.yml

server: 

  port: 8500 

eureka: 

  client: 

    #是否将自己注册到Eureka Server,默认为true,由于当前就是server,故而设置成false,表明该服务不会向eureka注册自己的信息 

    register-with-eureka: false 

    #是否从eureka server获取注册信息,由于单节点,不需要同步其他节点数据,用false 

    fetch-registry: false 

    #设置服务注册中心的URL,用于client和server端交流 

    service-url: 

      defaultZone: :8080/eureka/ 

2.3 服务端启动类

启动类上添加此注解标识该服务为配置中心@EnableEurekaServer

import org.springframework.boot.SpringApplication; 

import org.springframework.boot.autoconfigure.SpringBootApplication; 

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 

 

@EnableEurekaServer 

@SpringBootApplication 

public class EurekaServerApplication { 

 

    public static void main(String[] args) { 

        SpringApplication.run(EurekaServerApplication.class, args); 

    } 

2.4 启动

我们启动 EurekaDemoApplication,然后在浏览器中输入地址 :8500/,就可以启动我们的 Eureka 了,我们来看下效果,出现了这个画面,就说明我们已经成功启动~,只是此时我们的服务中是还没有客户端进行注册

本文来自网络,不代表站长网立场,转载请注明出处:https://www.tzzz.com.cn/html/biancheng/zx/2021/0602/8639.html

作者: dawei

【声明】:站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。
联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部