为了账号安全,请及时绑定邮箱和手机立即绑定

Spring Cloud Gateway 不适用于 @Bean Discovery

Spring Cloud Gateway 不适用于 @Bean Discovery

桃花长相依 2021-06-07 13:27:56
我遵循 Spring Tips: Spring Cloud Gateway。但是我的网关应用程序不会从服务注册(尤里卡)创建路由。带有 2 个参数的 DiscoveryClientRouteDefinitionLocator 构造函数。它不是从 Eureka 服务器路由的网关应用程序。我一直在尝试更改 pom.xml 中的版本,但我使用的是 RELEASE。该Application.java@SpringBootApplicationpublic 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=gatewayserver.port=8081eureka.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>
查看完整描述

2 回答

?
临摹微笑

TA贡献1982条经验 获得超2个赞

构造函数DiscoveryClientRouteDefinitionLocator (DiscoveryClient, DiscoveryLocatorProperties) 已弃用


我建议你使用:


ReactiveDiscoveryClient代替DiscoveryClient


@Bean

DiscoveryClientRouteDefinitionLocator discoveryRoutes(ReactiveDiscoveryClient rdc,

        DiscoveryLocatorProperties dlp) {

    return new DiscoveryClientRouteDefinitionLocator(rdc, dlp);

}

其他的事情,你应该将你的application.proporty重命名为application.properities


查看完整回答
反对 回复 2021-06-10
  • 2 回答
  • 0 关注
  • 250 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信