Eureka的配置和使注册

Eureka的系统架构图

在这里插入图片描述
我们可以理解为 Eureka 是一个写字楼,里面有很多办公区租给各个公司使用,M公司再写字楼中租了一层楼在前台注册后,需要交物业费,如果三个月没有交物业费的话就无法使用了。而小A是一名访客,进入M公司参观也需要在前台注册。这样的话在写字楼前台就会有公司登记信息,访客登记信息,公司与访客都是client。

cloud-eureka-server7001

这个Module好比是一个前台

1.引入pom依赖

		<!--eureka-server-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

注意是spring-cloud-starter-netflix-eureka-server而不是spring-cloud-starter-netflix-eureka-client

2.application.properties

配置如下:

server.port=7001

#eureka服务端的实例名称
eureka.instance.hostname=localhost
#false表示不向注册中心注册自己。
eureka.client.register-with-eureka=false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
eureka.client.fetch-registry=false
#设置与Eureka server交互的地址查询服务和注册服务都需要依赖这个地址。
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

3.在主启动类上加注解

@SpringBootApplication
@EnableEurekaServer //Eureka注解
public class EurekaMain7001 {
    public static void main(String[] args) {
        SpringApplication.run(EurekaMain7001.class,args);
    }
}

4.自测

访问http://localhost:7001,出现下面标识则配置成功
在这里插入图片描述

cloud-provider-payment8001

这个Module好比是M公司,需要在前台进行注册

1.引入pom依赖

        <!--eureka-server-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

此时作为client进行访问

2.application.properties

server.port=8001
#名字不要轻易变动,会在http://localhost:7001上显示
spring.application.name=cloud-payment-service

#表示是否将自己注册进Eurekaserver默认为true。
eureka.client.register-with-eureka=true
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
eureka.client.fetch-registry=true
#入住地址
eureka.client.service-url.defaultZone=http://localhost:7001/eureka

3.在主启动类上加注解

@MapperScan("com.winky.springcloud.mapper")
@ServletComponentScan(basePackages = "com.winky.springcloud")
@SpringBootApplication
@EnableEurekaClient
public class PaymentMain8001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain8001.class, args);
    }
}

4. 同理处理cloud-consumer-order8080

5. 自测

在这里插入图片描述

如果出现上图则说明注册成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值