设置问题 spring 云网关

Issue setting up spring cloud gateway

我正在尝试为测试项目设置 spring 云网关,但是当我使用“lb://”时它总是失败 url.

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>

4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.1 com.blar 测试 0.0.1-快照 测试 Spring Boot

的演示项目
<properties>
    <java.version>11</java.version>
    <kotlin.version>1.4.21</kotlin.version>
    <spring-cloud.version>2020.0.0-M6</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <configuration>
                <args>
                    <arg>-Xjsr305=strict</arg>
                </args>
                <compilerPlugins>
                    <plugin>spring</plugin>
                </compilerPlugins>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-allopen</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>

这是我的路由功能

 @Bean
fun customRouteLocator(builder: RouteLocatorBuilder): RouteLocator? {
    return builder.routes()
            .route("nitro-service") { r: PredicateSpec ->
                r.path("/nitro")
                        .uri("lb://nitro-service")
            }
            .build()
}

这是我得到的错误

java.net.UnknownHostException: failed to resolve 'DESKTOP' after 10 queries 
at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1013) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 

如果我指定实际的 url 它工作正常但是当我尝试将它与尤里卡结合时抛出这个错误。这是一个非常基础的项目,因此在路由功能之外的网关中没有代码。

我在使用 Spring Boot 2.4 和 WebClient Netty 时遇到了类似的 DNS 解析问题。 我使用了这个解决方法:

HttpClient.create().resolver(DefaultAddressResolverGroup.INSTANCE)

此处问题描述:https://github.com/reactor/reactor-netty/issues/1431