0

我比较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;

就是这样。任何帮助将不胜感激!

4

1 回答 1

1

我有同样的问题,我做了调查,我发现 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>
于 2020-05-26T18:42:32.383 回答