1.Ribbon注册服务内部调用

1.在搭建完成服务注册中心和注册服务后,服务消费项目pom.xml加入ribbon依赖

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

2.服务消费项目配置文件application.yml加服务信息配置

eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:8001/eureka/  #注册中心地址
#与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址,默认是http://localhost:800#1/eureka;多个地址可用,分隔

3.服务调用项目启动类加@EnableDiscoveryClient注解

@SpringBootApplication
@EnableDiscoveryClient//开启发现服务功能
public class ServiceConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run

版权声明:本文为huangchong0107原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。