我已经配置了一个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..."?
这是微服务中的错误日志,它似乎正在尝试本地主机和标准端口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]发布于 2018-09-28 17:07:41
我最终发现当前的Eureka Server中存在一个bug,如下面的答案所述:
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();
}
}
}https://stackoverflow.com/questions/52550554
复制相似问题