服务注册中心之erueka(单机版)

Posted bjrun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了服务注册中心之erueka(单机版)相关的知识,希望对你有一定的参考价值。

由于spring官方集成了eureka,所以在我们使用时,特别方便。

使用springboot创建eureka服务注册中心(单机版)

1. 在pom.xml中添加以下依赖项

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2.在application.yml中添加以下内容
server:
port: 7001 #服务端口

eureka:
instance:
hostname: localhost #eureka服务端的实例名字
client:
register-with-eureka: false #表识不向注册中心注册自己
fetch-registry: false #表示自己就是注册中心,职责是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://localhost:7001/eureka/ #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址
3.开发主启动类

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

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServerMain7001.class,args);
}
}
注意:启动类上需要添加@SpringBootApplication肯EnableEurekaServer注解

4.运行主启动类
5.在浏览器中输入http://localhost:7001,查看是否出现如下页面

技术图片

如果出现此页面,表示单机版eureka服务注册中心,已经搭建完毕!

以上是关于服务注册中心之erueka(单机版)的主要内容,如果未能解决你的问题,请参考以下文章

eureka注册中心单机

二Spring Cloud之注册中心 Eureka

微服务注册中心分布式集群设计原理与 Golang 实现

springcloud:服务提供与调用

springcloud:服务提供与调用

springcloud:服务提供与调用