Spring Cloud Gateway 不适用于 @Bean Discovery

我遵循 Spring Tips: Spring Cloud Gateway。但是我的网关应用程序不会从服务注册(尤里卡)创建路由。带有 2 个参数的 DiscoveryClientRouteDefinitionLocator 构造函数。它不是从 Eureka 服务器路由的网关应用程序。我一直在尝试更改 pom.xml 中的版本,但我使用的是 RELEASE。


该Application.java


@SpringBootApplication

public class GatewayApplication {


    @Bean

    DiscoveryClientRouteDefinitionLocator discoveryRoutes(DiscoveryClient dc, DiscoveryLocatorProperties dlp) {

        return new DiscoveryClientRouteDefinitionLocator(dc, dlp);

    }


    public static void main(String[] args) {

        SpringApplication.run(GatewayApplication.class, args);

    }

}

DiscoveryClientRouteDefinitionLocator 的构造函数现在使用 2 个参数,而不是像 Spring Tips: Spring Clou Gateway 中的 1 个参数。


该application.property:


spring.application.name=gateway

server.port=8081

eureka.client.register-with-eureka=true

我的pom.xml:


<?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>


<groupId>com.hcl.cnp</groupId>

<artifactId>gateway</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>


<name>gateway</name>

<description>Demo project for Spring Boot</description>


<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>2.0.3.RELEASE</version>

    <relativePath/> <!-- lookup parent from repository -->

</parent>


<properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <java.version>1.8</java.version>

    <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>

</properties>


<dependencies>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-actuator</artifactId>

    </dependency>


桃花长相依
浏览 251回答 2
2回答

临摹微笑

构造函数DiscoveryClientRouteDefinitionLocator (DiscoveryClient, DiscoveryLocatorProperties) 已弃用我建议你使用:ReactiveDiscoveryClient代替DiscoveryClient@BeanDiscoveryClientRouteDefinitionLocator discoveryRoutes(ReactiveDiscoveryClient rdc,&nbsp; &nbsp; &nbsp; &nbsp; DiscoveryLocatorProperties dlp) {&nbsp; &nbsp; return new DiscoveryClientRouteDefinitionLocator(rdc, dlp);}其他的事情,你应该将你的application.proporty重命名为application.properities
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java