Spring boot Spring云网关路由器总是给出404错误
我有一个SpringCloud项目。该项目包括三个主要部分:使用Spring boot Spring云网关路由器总是给出404错误,spring-boot,spring-cloud,spring-cloud-gateway,Spring Boot,Spring Cloud,Spring Cloud Gateway,我有一个SpringCloud项目。该项目包括三个主要部分:使用Eureka的服务发现,使用Spring云网关的网关,以及针对restapi端点的服务。我想这样定义API端点: GET /available 并使用网关中的路径谓词对其进行路由: GET /service-one/available 为了实现这一点,我在gateway的yml文件中添加了以下路由: spring: cloud: gateway: routes:
Eureka
的服务发现,使用Spring云网关的网关,以及针对restapi端点的服务。我想这样定义API端点:
GET
/available
并使用网关中的路径谓词对其进行路由:
GET
/service-one/available
为了实现这一点,我在gateway的yml文件中添加了以下路由:
spring:
cloud:
gateway:
routes:
- id: service_one
uri: lb://service_one
predicates:
- Path=/service-one/**
filters:
- StripPrefix=1
但是当我尝试的时候
// 9000 is the gateway's port number
http://localhost:9000/service-one/available
我得到这个错误:
{
"timestamp": "...",
"path": "/service-one/available",
"status": 404,
"error": "Not Found",
"message": null,
"requestId": "..."
}
更多详情:
Spring启动版本:2.4.5
Spring云版本:2020.0.2
- 发现:
pom.xml
:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
应用程序启动:
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApplication {
// ...
}
- 网关:
pom.xml
:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 服务:
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
服务端点:
@SpringBootApplication
@EnableEurekaClient
@RestController
public class ServiceOneApplication {
// ...
@GetMapping("/available")
public String available() {
return "Hi, Service One is available";
}
}
@你好,你能帮我吗?你找到解决办法了吗?目前我正在做另一个项目。
@SpringBootApplication
@EnableEurekaClient
@RestController
public class ServiceOneApplication {
// ...
@GetMapping("/available")
public String available() {
return "Hi, Service One is available";
}
}