码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-06-15 13:43:40      阅读:41      评论:0      收藏:0      [点我收藏+]

标签:public   void   end   注解   pom   zone   imp   交互   img   

由于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(单机版)

标签:public   void   end   注解   pom   zone   imp   交互   img   

原文地址:https://www.cnblogs.com/bjrun/p/13130184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!