一、网关

1. 依赖

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.cloud</groupId>
  7. <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
  8. </dependency>

2. 主启动类

添加@EnableZuulProxy 注解

@EnableZuulProxy
@SpringBootApplication
public class CrowdMainClass {
    public static void main(String[] args) {
        SpringApplication.run(CrowdMainClass.class);
    }
}

3. application.yaml

server:
  port: 80

zuul:
  routes:
    user:                         # 自定义路由规则的名称,在底层是一个Map的key
      serviceId: yixuexi-crowd-auth # 目标微服务名称,ZuulRoute类型的一个属性
      path: /**         # 用来代替目标微服务名称的路径,ZuulRoute类型的一个属性
      # /**表示比配多层路径, 如果没有/**则不能匹配后续的多层路径了
    #ignored-services:     # 忽略指定微服务名称,让用户不能通过微服务名称访问
    # - consumer-service
  ignored-services: '*'  # 忽略所有微服务名称
  sensitive-headers: "*" # 在zuul向其他微服务重定向是保持原本头信息(请求头,响应头)
eureka:
  client:
    service-url:
      defaultZone: http://localhost:1000/eureka