server:
port: 9996
spring:
security:
user:
name: admin
password: 123456
cloud:
gateway:
enabled: true
loadbalancer:
use404: true
discovery:
locator:
enabled: true
lower_case_service_id: true
routes:
- id: baidu
uri: https://www.baidu.com
predicates:
- Path=/baidu
filters:
- StripPrefix=1
- id: path
uri: http://127.0.0.1:8090
predicates:
- Path=/demo
filters:
- StripPrefix=1
- id: nacos
uri: http://10.10.10.99:30018/nacos/#/serviceManagement?dataId=&group=&appName=&namespace=&pageSize=&pageNo=
predicates:
- Path=/nacos
filters:
- StripPrefix=1
#设置的id是dubbo-starter-reference
- id: reference
#网关不设置上下问,服务存在上下问情况
#找不到lb实例,这种写法管用的 http://dubbo-starter-reference:9997,-Path设置为 - Path=/dubbo-reference/**
uri: lb://dubbo-starter-reference
predicates:
- Path=/reference/**
filters:
##由于微服务dubbo-starter-reference中设置了server.servlet.context-path=/dubbo-starter-reference,要重写路径才能正常路由到该微服务
- RewritePath=/reference/?(?<segment>.*), /dubbo-starter-reference/$\{segment}
management:
endpoint:
gateway:
#默认是true
enabled: true
endpoints:
web:
exposure:
#一直存在的
include: "*"
hystrix:
command:
default:
execution:
isolation:
strategy: SEMAPHORE
thread:
timeoutInMilliseconds: 3000
shareSecurityContext: true
上面是网关的简单配置,使用http://dubbo-starter-reference:9997可以访问成功
进入gateway的pod容器,连接dubbo-starter-reference实例正常,
将uri: lb://dubbo-starter-reference,访问接口出现404的错误。
描述:pom.xml描述,配置了actuator,并且application.yaml中设置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.3</version> <relativePath/> </parent> <artifactId>gateway-gateway</artifactId> <name>gateway-gateway</name> <version>0.0.1-SNAPSHOT</version> <properties> <swagger.version>2.9.2</swagger.version> </properties> <dependencies> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.6</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2021.0.1.0</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2021.0.1.0</version> </dependency&