SpringBoot 2.0.3.RELEASE

SpringCloud Finchley.RELEASE

启动 eureka 客户端,报如下错误:

2019-02-01 11:36:56.933  INFO 388404 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2019-02-01 11:36:56.933  INFO 388404 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2019-02-01 11:36:57.375  INFO 388404 --- [           main] com.netflix.discovery.DiscoveryClient    : The response status is 200
2019-02-01 11:36:57.377  INFO 388404 --- [           main] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 30
2019-02-01 11:36:57.380  INFO 388404 --- [           main] c.n.discovery.InstanceInfoReplicator     : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-02-01 11:36:57.385  INFO 388404 --- [           main] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1548992217383 with initial instances count: 0
2019-02-01 11:36:57.389  INFO 388404 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application sc-config-server with eureka with status UP
2019-02-01 11:36:57.390  INFO 388404 --- [           main] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1548992217390, current=UP, previous=STARTING]
2019-02-01 11:36:57.392  INFO 388404 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_SC-CONFIG-SERVER/sc-config-server:8800: registering service...
2019-02-01 11:36:57.469  INFO 388404 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8800 (http) with context path ''
2019-02-01 11:36:57.470  INFO 388404 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8800
2019-02-01 11:36:57.475  INFO 388404 --- [           main] com.fhbean.sb2sc.ScConfigApplication     : Started ScConfigApplication in 12.616 seconds (JVM running for 14.483)
2019-02-01 11:36:57.495  WARN 388404 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failure with status code 403; retrying on another server if available
2019-02-01 11:36:57.502  WARN 388404 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_SC-CONFIG-SERVER/sc-config-server:8800 - 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.2.jar:1.9.2]
	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.2.jar:1.9.2]
	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.9.2.jar:1.9.2]
	at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.2.jar:1.9.2]
	at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.2.jar:1.9.2]
	at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829) ~[eureka-client-1.9.2.jar:1.9.2]
	at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) [eureka-client-1.9.2.jar:1.9.2]
	at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:101) [eureka-client-1.9.2.jar:1.9.2]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]

客户端的application.yml配置如下:

server:
  port: 8800

spring:
  security:
    basic:
      enabled: true
    user:
      name: root
      password: booszy
  application:
    name: sc-config-server
  cloud:
    config:
      server:
        git:
          uri: https://git.coding.net/yirenyishi/springcloud-config-profile
          search-paths: '{application}'

eureka:
  client:
    service-url:
      defaultZone: http://root:booszy@localhost:8761/eureka/

  instance:
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
    appname: sc-config-server

eureka服务端的application.yml配置如下:

server:
  port: 8761

eureka:
  datacenter: trmap
  environment: product
  server:
    # 关闭自我保护
    enable-self-preservation: false
    # 清理服务器
    eviction-interval-timer-in-ms: 5000
  client:
    healthcheck:
      enabled: true
    service-url:
      defaultZone: http://root:booszy@localhost:8761/eureka/
    register-with-eureka: false
    fetch-registry: false

spring:
  security:
    basic:
      enabled: true
    user:
      name: root
      password: booszy

出现这个错误提示,有两种可能:

1、defaultZone的地址拼写错误,比如

把defaultZone拼写为defalutZone,或者defaultZone后面没有冒号,或冒号后面没有空格等

把service-url拼写错,等

总之eureka.client.service-url.defaultZone写错一个字母都会报此错误

2、新版的security默认启用了csrf检验,要在eureka服务端那边配置security的csrf检验为false

在server端,编写如下代码,再重启server和client

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

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐