企业网站推广品牌,西安建站模板,上海外贸,网站如何不被收录Spring Cloud Gateway 是一个用于构建 API 网关的项目#xff0c;它是 Spring Cloud 生态系统中的一部分#xff0c;旨在为微服务架构提供动态路由、负载均衡、安全性和监控等功能。 网关工程对应pom文件
?xml version1.0 encodingUTF-8?… Spring Cloud Gateway 是一个用于构建 API 网关的项目它是 Spring Cloud 生态系统中的一部分旨在为微服务架构提供动态路由、负载均衡、安全性和监控等功能。 网关工程对应pom文件
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.xuecheng/groupIdartifactIdxuecheng-plus-parent/artifactIdversion0.0.1-SNAPSHOT/versionrelativePath../xuecheng-plus-parent/relativePath/parentartifactIdxuecheng-plus-gateway/artifactIddependencies!--网关--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependency!--服务发现中心--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependencydependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-config/artifactId/dependencydependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency!-- 排除 Spring Boot 依赖的日志包冲突 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactIdexclusionsexclusiongroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-logging/artifactId/exclusion/exclusions/dependency!-- Spring Boot 集成 log4j2 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-log4j2/artifactId/dependency/dependencies/project工程对应的bootstrap.yaml
#微服务配置
spring:application:name: gatewaycloud:nacos:server-addr: 192.168.101.65:8848discovery:namespace: dev402group: xuecheng-plus-projectconfig:namespace: dev402group: xuecheng-plus-projectfile-extension: yamlrefresh-enabled: trueshared-configs:- data-id: logging-${spring.profiles.active}.yamlgroup: xuecheng-plus-commonrefresh: trueprofiles:active: dev
Nacos对应网关配置文件
server:port: 63010 # 网关端口
spring:cloud:gateway:
# filter:
# strip-prefix:
# enabled: trueroutes: # 网关路由配置- id: content-api # 路由id自定义只要唯一即可# uri: http://127.0.0.1:8081 # 路由的目标地址 http就是固定地址uri: lb://content-api # 路由的目标地址 lb就是负载均衡后面跟服务名称predicates: # 路由断言也就是判断请求是否符合路由规则的条件- Path/content/** # 这个是按照路径匹配只要以/content/开头就符合要求
# filters:
# - StripPrefix1- id: system-api# uri: http://127.0.0.1:8081uri: lb://system-apipredicates:- Path/system/**
# filters:
# - StripPrefix1- id: media-api# uri: http://127.0.0.1:8081uri: lb://media-apipredicates:- Path/media/**
# filters:
# - StripPrefix1- id: search-service# uri: http://127.0.0.1:8081uri: lb://searchpredicates:- Path/search/**
# filters:
# - StripPrefix1- id: auth-service# uri: http://127.0.0.1:8081uri: lb://auth-servicepredicates:- Path/auth/**
# filters:
# - StripPrefix1- id: checkcode# uri: http://127.0.0.1:8081uri: lb://checkcodepredicates:- Path/checkcode/**
# filters:
# - StripPrefix1- id: learning-api# uri: http://127.0.0.1:8081uri: lb://learning-apipredicates:- Path/learning/**
# filters:
# - StripPrefix1- id: orders-api# uri: http://127.0.0.1:8081uri: lb://orders-apipredicates:- Path/orders/**
# filters:
# - StripPrefix1
测试
这个时候请求就可以直接使用网关对应的ipport进行接口请求了