Eureka注册中心搭建步骤(eureka-server)

1.创建一个maven工程作为父级

在该maven工程的pom文件中添加springcloud所有组件,必须基于springboot自动才能实现

<!--springcloud所有组件,必须基于springboot自动才能实现-->
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.2.5.RELEASE</version>
</parent>

继续在该pom文件中添加依赖,作为父级工程定义版本

<!--不在子工程定义不同组件的版本号,统一由父工程定义版本-->
<dependencyManagement>
  <!--springcloud考虑boot对应关系比较复杂-->
  <!--导入springcloud版本总依赖,和当前springboot所有组件对应统一了-->
  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Hoxton.SR3</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

2.创建一个idea模块Module,作为上述父级工程的子工程

在子工程的pom文件中添加依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--eureka-server依赖-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
</dependencies>

在子工程中添加启动器及配置文件

启动类中注意添加2个注解

@SpringBootApplication
//开启eureka服务端注解
@EnableEurekaServer
public class StarterEurekaServer {
    public static void main(String[] args) {
        SpringApplication.run(StarterEurekaServer.class,args);
    }
}

配置文件中 因为是作为注册中心,所以需要关闭抓取和注册(因为是作为服务端使用),指定端口

fetch-registry :抓取注册信息

register-with-eureka注册到eureka服务端

#port
server.port=8761
#注册中心组件配置属性
#客户端角色
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false

3.配置完成,启动服务,在浏览器端输入地址+端口即可访问

,因为此时,没有服务注册进来所以application处无信息

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值