pom依赖
<!--gateway-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
配置
spring:
application:
name: gateway
cloud:
consul:
host: localhost
port: 8500
discovery:
# 设置不需要注册到 consul 中
register: true
gateway:
discovery:
locator:
enabled: true
routes:
# 路由ID
- id: system-route
# 目标服务地址
uri: http://localhost:8211/**
# 路由条件,Predicate 接受一个输入参数,返回一个布尔值结果。该接口包含多种默认方法来将 Predicate 组合成其他复杂的逻辑(比如:与,或,非)。
predicates:
- Path=/system/**
# 说明:访问Path时服务前缀自动改为uri
- id: erp-route
uri: http://localhost:8303/**
predicates:
- Path=/erp/**
问题
报错:Error creating bean with name ‘bootstrapImportSelectorConfiguration’
解决:清空依赖包重新导入报错:‘org.springframework.http.codec.ServerCodecConfigurer’ that could not be found.
解决:依赖冲突:gateway依赖和web依赖冲突,如果不需要spring-boot-starter-web服务则取消引入,非要web支持的话需要导入spring-boot-starter-webflux(原因是springcloud升级了,不再使用springwebmvc而是webflux,启动要去除spring-boot-starter-web及spring-webmvc)
更多说明参考:
报错:请求403,gateway跨域
WebMvcConfigurer
因为:取消引入spring-boot-starter-web
所以:https://blog.csdn.net/zhanghuan0303/article/details/106474046/
取消引入又手动添加,不太好
非WebMvcConfigurer解决跨域:
参考
版权声明:本文为u012382791原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。