学习博客:【SpringCloud】Gateway配置

2022-09-07 13:46:53

SpringBoot版本:2.7.1
SpringCloud版本:2021.0.3
简单学习了下Gateway的配置
首先导入依赖,下方链接是使用过程中遇到的问题
使用Gateway出现Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><!--Hystrix--><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>2.2.10.RELEASE</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId><version>2.2.10.RELEASE</version><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></exclusion></exclusions></dependency><!-- https://mvnrepository.com/artifact/com.netflix.ribbon/ribbon-loadbalancer --><dependency><groupId>com.netflix.ribbon</groupId><artifactId>ribbon-loadbalancer</artifactId><version>2.7.18</version></dependency><!--Eureka 已集成Ribbon、Feign--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId><version>1.4.7.RELEASE</version></dependency><!--actuaor 完善监控信息--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId></dependency></dependencies>

配置文件

server:port:9527spring:application:name: springcloud-gatewaycloud:gateway:enabled:trueroutes:-id: springcloud_provider_dept#路由的ID,没有固定规则但要求唯一,建议配合服务名uri: http://localhost:8001#匹配后提供服务的路由地址predicates:#路由断言,判断请求是否符合规则- Path=/mydept/dept/**#路径断言,判断路径是否是以/mydept开头,如果是则符合filters:- RewritePath=/mydept/(?<segment>/?.*), /$\{segment}-id: blog_testuri: https://www.csdn.net/predicates:- Query=url,blogeureka:client:service-url:defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/instance:instance-id: gateway9527.comprefer-ip-address:truemanagement:endpoints:web:exposure:include:"*"info:env:enabled:true# 暴露端点infoinfo:app.name: yl-springcloudcompany.name: www.yl.combuild.artifactId: com.yl.springcloudbuild.version: 1.0-SNAPSHOT

主启动类

@SpringBootApplication@EnableEurekaClientpublicclassZuulApplication_9527{publicstaticvoidmain(String[] args){SpringApplication.run(ZuulApplication_9527.class,args);}}

在这里插入图片描述
在这里插入图片描述

  • 作者:Aurinko.
  • 原文链接:https://aurinko.blog.csdn.net/article/details/125667151
    更新时间:2022-09-07 13:46:53