首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kubernetes服务发现中的Spring云网关配置问题

Kubernetes服务发现中的Spring云网关配置问题
EN

Stack Overflow用户
提问于 2019-10-13 18:41:29
回答 1查看 772关注 0票数 1

我试图在kubernetes服务发现中使用spring云网关。下面是我正在使用的设置

build.gradle

代码语言:javascript
复制
plugins {
    id 'org.springframework.boot' version '2.2.0.BUILD-SNAPSHOT'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://repo.spring.io/snapshot' }
}

ext {
    set('springCloudVersion', "Hoxton.BUILD-SNAPSHOT")
    set('springCloudKubernetesVersion', "1.0.3.RELEASE")
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
    implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes'
    implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-ribbon'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        mavenBom "org.springframework.cloud:spring-cloud-kubernetes-dependencies:${springCloudKubernetesVersion}"
    }
}

test {
    useJUnitPlatform()
}

application.yml

代码语言:javascript
复制
spring:
  application.name: gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
    kubernetes:
      reload:
        enabled: true
server:
  port: 8080
logging:
  level:
    org.springframework.cloud.gateway: TRACE
    org.springframework.cloud.loadbalancer: TRACE
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      enabled: true
    info:
      enabled: true

DemoApplication.java

代码语言:javascript
复制
package com.example.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class DemoApplication {

    @Autowired
    private DiscoveryClient discoveryClient;
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/services")
    public List<String> services() {
      return this.discoveryClient.getServices();
    }
}

Spring云网关无法将请求重定向到其他服务。正在打印的日志是

2019年-10-13 18:29:38.303痕量1-或-http-epoll-2 o.s.c.g.f.WeightCalculatorWebFilter :重量:{} 2019-10-13 18:29:38.305

虽然当我调用http://<gateway-url>/services时,我可以看到所有服务的列表。因此,所有的许可都是在吊舱级提供的,服务发现也很好。我很确定有一些配置,这是我所缺少的,但即使在多次查看文档之后,我也无法找到它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-20 07:14:13

因此,看起来Spring Hoxton.M3发布版中存在一个问题,因为它在Hoxton.M2中运行得很好。

我也开了一个问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58366684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档