美文网首页
Spring Cloud 第一代网关 Zuul

Spring Cloud 第一代网关 Zuul

作者: Tinyspot | 来源:发表于2023-01-03 23:11 被阅读0次

API 网关

  • 路由表
  • 链路追踪

1.1 网关的作用

  1. 路由:接口服务的统一代理,实现前端对接口的统一访问
  2. 过滤:对用户请求进行拦截、过滤(用户鉴权)、监控
  3. 限流:限制用户的访问流量

1.2 常用网关

  • Nginx
  • Spring Cloud Netflix zuul
  • Spring Cloud Gateway

2. Zuul 网关

  • 路由转发
  • 过滤器
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>
</dependencies>

application.yml

zuul:
  routes:
    api:
      path: /api/**
      serviceId: concrete-eureka-client # spring.application.name
    apiB:
      path: /api/b/**
      serviceId: concrete-feign

增加注解 @EnableZuulProxy
@EnableZuulProxy 是 @EnableZuulServer 的增强升级版

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

报错:
java.lang.NoSuchMethodError: org.springframework.boot.web.servlet.error.ErrorController.getErrorPath()Ljava/lang/String;
zuul 版本与 Spring Cloud 版本冲突

相关文章

网友评论

      本文标题:Spring Cloud 第一代网关 Zuul

      本文链接:https://www.haomeiwen.com/subject/inumgrtx.html