加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 编程要点 > 资讯 > 正文

Eureka单节点构建的高效处理

发布时间:2021-06-02 14:27:34 所属栏目:资讯 来源:互联网
导读:在有的教程中,会引入 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 了,我们来看下效果,出现了这个画面,就说明我们已经成功启动~,只是此时我们的服务中是还没有客户端进行注册

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读