API 网关
- 路由表
- 链路追踪
1.1 网关的作用
- 路由:接口服务的统一代理,实现前端对接口的统一访问
- 过滤:对用户请求进行拦截、过滤(用户鉴权)、监控
- 限流:限制用户的访问流量
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 版本冲突
网友评论