首页 文章

无法在Eureka注册我的微服务

提问于
浏览
0

我配置了一台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'
    }
}

这是我的配置 . 我已将它包含在bootstrap.yaml和配置服务器中,以确保:

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

但由于某种原因,它被忽略了 . 该属性的根源是“eureka”,而不是“spring.eureka ......”?

这是微服务中的错误日志,它似乎在尝试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

    我终于发现当前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();
            }
        }
    }
    

相关问题