一、网关
常用网关gateway,zuul 等。 gateway和spring-cloud兼容的更好,约占70%的市场。
二、基本使用
1、导入gateway网关依赖
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.4.2</spring-boot.version>
<spring-cloud.version>2020.0.6</spring-cloud.version>
</properties>
<dependencies>
<!-- 网关与其他web服务冲突,需要注销掉其他web服务-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
</dependencies>
2、配置网关的配置文件
# 应用服务 WEB 访问端口
server:
port: 8081
spring:
application:
name: gateway
cloud:
gateway:
routes:
- id: ribbonA-server #不重复即可
uri: http://localhost:8081/ #服务需要转发的地址
predicates:
- Path=/a/** #代理路径
filters:
- StripPrefix=1
3、添加启动类开关
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient #启动gateway启动类开关
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
标签:网关,服务,spring,springframework,使用,org,gateway,cloud From: https://www.cnblogs.com/chuanghongmeng/p/17994440