springcloud搭建(五)eureka注册中心

本文详细介绍了如何通过添加依赖jar包、配置application.yml文件及编写启动类来搭建Eureka注册中心,实现微服务架构中服务的注册与发现。

1.添加依赖jar包

<dependencies>
         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <!-- 修改后立即生效,热部署 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
  </dependencies>

2.编写application.yml

server:
  port: 2001
  context-path: /
  
eureka: 
  instance:
    # 单机 hostname: localhost #eureka注册中心实例名称
    hostname: eureka2001.java1234.com # 集群
  client: 
    register-with-eureka: false     #false 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己。
    fetch-registry: false     #false 由于注册中心的职责就是维护服务实例,它并不需要去检索服务,所以也设置为false
    service-url: 
       defaultZone: http://eureka2002.java1234.com:2002/eureka/,http://eureka2003.java1234.com:2003/eureka/ # 集群
       #单机defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/       #设置与Eureka注册中心交互的地址,查询服务和注册服务用到       #设置与Eureka注册中心交互的地址,查询服务和注册服务用到

3.编写启动类:

package com.java1234;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
 
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication_2001 {
 
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication_2001.class, args);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值