我对spring-cloud-gateway
相对较新,我正在为其构建POC。我制作了一个示例网关应用程序和一个微服务应用程序。我已经验证了微服务应用程序运行良好,并且可以在port: 8080
上访问
这两个应用程序都运行良好。因此,我在此不共享POMs
。但是,请参阅下面的代码详细信息。
网关
application.yml
server:
port: 8081
spring:
cloud:
gateway:
routes:
- id: microserviceFirst
uri: localhost:8080
predicates:
- Path= /first
management:
endpoints:
web:
exposure:
include: "*"
the springboot app
:
package com.ey.springCloudGateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringCloudGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudGatewayApplication.class, args);
}
}
微服务应用
application.properties
spring.application.name="microserviceFirst"
server.port=8080
springboot file
package com.ey.microserviceFirst;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class MicroserviceFirstApplication {
@RequestMapping(value = "/", method = RequestMethod.GET)
public Map<String, Object> home() {
Map<String, Object> model = new HashMap<String, Object>();
model.put("id", UUID.randomUUID().toString());
model.put("content", "Hello World");
return model;
}
public static void main(String[] args) {
SpringApplication.run(MicroserviceFirstApplication.class, args);
}
}
我正试图使用邮递员访问localhost:8081/first
。以下是错误。
java.lang.NoSuchMethodError: reactor.netty.http.client.HttpClient.noChunkedTransfer()Lreactor/netty/http/client/HttpClient;
就这样。如有任何帮助,我们将不胜感激!
我也遇到了同样的问题,我做了一项调查,发现spring-boot(父母云和网关云(的版本不同,然后我可以在这个页面中看到(https://www.javainuse.com/spring/cloud-gateway)示例和另一页(https://blog.csdn.net/h363659487/article/details/102780475)解决方案。
我希望能有所帮助。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>