Java Spring云网关未找到路由路径(404错误)
我正在研究SpringCloudGateway作为专业应用程序的API网关解决方案,并正在运行本教程: 然而,我遇到了我无法解决的问题 这是我的POMJava Spring云网关未找到路由路径(404错误),java,spring-cloud-gateway,Java,Spring Cloud Gateway,我正在研究SpringCloudGateway作为专业应用程序的API网关解决方案,并正在运行本教程: 然而,我遇到了我无法解决的问题 这是我的POM <groupId>org.springframework</groupId> <artifactId>gs-gateway</artifactId> <version>0.1.0</version> <parent> <groupId>org
<groupId>org.springframework</groupId>
<artifactId>gs-gateway</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RC2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
运行这个并尝试点击会给我一个网关超时。咨询工作人员时,我发现我在防火墙后面,需要一个代理。因此,我将Application.java修改为:
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(p -> p.host("internet.proxy.*****.com").and()
.path("/get")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri("http://httpbin.org:80"))
.build();
}
现在,我不再得到网关超时,但现在我得到一个404错误。以下是使用curl的输出:
我可能错过了一些简单的东西,但我看不到
编辑:
根据上面列出的教程,这应该是我得到的回复:
{
"args": {},
"headers": {
"Accept": "*/*",
"Connection": "close",
"Forwarded":
"proto=http;host=\"localhost:8080\";for=\"0:0:0:0:0:0:0:1:56207\"",
"Hello": "World",
"Host": "httpbin.org",
"User-Agent": "curl/7.54.0",
"X-Forwarded-Host": "localhost:8080"
},
"origin": "0:0:0:0:0:0:0:1, 73.68.251.70",
"url": "http://localhost:8080/get"
}
删除代码中的
@RestController
您必须将主机
标题设置为“internet.proxy.*****.com”
您连接了主机谓词和路径谓词
curl--header“Host:internet.proxy.test.com”http://localhost:8080/get
{"timestamp":"2019-01-
16T14:24:12.929+0000","path":"/get","status":404,"error":"Not
Found","message":null}
{
"args": {},
"headers": {
"Accept": "*/*",
"Connection": "close",
"Forwarded":
"proto=http;host=\"localhost:8080\";for=\"0:0:0:0:0:0:0:1:56207\"",
"Hello": "World",
"Host": "httpbin.org",
"User-Agent": "curl/7.54.0",
"X-Forwarded-Host": "localhost:8080"
},
"origin": "0:0:0:0:0:0:0:1, 73.68.251.70",
"url": "http://localhost:8080/get"
}