Не могу зарегистрировать мои микросервисы в Eureka - PullRequest
0 голосов
/ 28 сентября 2018

У меня настроен сервер Eureka (он работает, так как я могу подключиться к нему и увидеть консоль Eureka), но мой микросервис не регистрируется на нем.Я получаю ошибку сервера 403 (Запрещено).Конфигурация аутентификации в микросервисе, пытающемся зарегистрироваться, кажется нормальной, как будто я намеренно установил ее неправильно, я получаю 401.

Моя конфигурация gradle:

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
        gradleDockerVersion   = '1.2'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE"
        classpath("se.transmode.gradle:gradle-docker:${gradleDockerVersion}")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
ext {
    springCloudVersion = 'Finchley.RELEASE'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
        mavenBom 'org.springframework.cloud:spring-cloud-netflix:2.0.1.RELEASE'
    }
}

Это моя конфигурация.Я включил его bith в bootstrap.yaml и в сервер конфигурации, просто чтобы убедиться:

eureka:
  client:
    serviceUrl:
      defaultZone: http://myuserid:mypassword@localhost:8761/eureka/

Но по какой-то причине он игнорируется.Корнем этого свойства является «eureka», а не «spring.eureka ...»?

Вот журнал ошибок в Microservice, который, похоже, пытается использовать localhost и стандартный порт 8080, следовательно, игнорируя конфигурацию выше.

2018-09-28 09:31:12.763  INFO 58552 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_MTPMS_WEATHER/localhost:mtpms_weather:8080: registering service...
2018-09-28 09:31:12.767  INFO 58552 --- [  restartedMain] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2018-09-28 09:31:12.768  INFO 58552 --- [  restartedMain] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2018-09-28 09:31:12.803  WARN 58552 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure with status code 403; retrying on another server if available
2018-09-28 09:31:12.808  WARN 58552 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_MTPMS_WEATHER/localhost:mtpms_weather:8080 - registration failed Cannot execute request on any known server

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
    at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.9.3.jar:1.9.3]

1 Ответ

0 голосов
/ 28 сентября 2018

Я наконец-то обнаружил, что в текущем Eureka Server есть ошибка, описанная в этом ответе:

https://github.com/spring-cloud/spring-cloud-netflix/issues/2754#issuecomment-372808529

Итак, добавление следующего фрагмента кода @EnableWebSecurity в Gateway Spring Bootкласс сервера приложений исправляет это:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
@SpringBootApplication
public class DiscoveryApplication {
    public static void main(String[] args) {
        new SpringApplicationBuilder(DiscoveryApplication.class).run(args);
    }

    @EnableWebSecurity
    static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();
        }
    }
}
...