com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

后端 未结 10 1618
眼角桃花
眼角桃花 2020-12-30 19:32

I am very new to the microservices and trying to run the code from link: https://dzone.com/articles/advanced-microservices-security-with-spring-and-oa . When I simply run th

相关标签:
10条回答
  • 2020-12-30 20:22

    If your eureka server is deployed/running without username and password use below properties.

    spring.application.name=Hello-World
    eureka.client.serviceUrl.defaultZone=http://eurekaserver:password@localhost:9100/eureka
    server.port=9200
    eureka.client.fetch-registry=true
    

    If your eureka server is deployed/running with username and password use below properties.

    spring.application.name=Hello-World
    eureka.client.serviceUrl.defaultZone=http://eurekaserverusername:eurekaserverpassword@localhost:9100/eureka
    server.port=9200
    eureka.client.fetch-registry=true
    
    0 讨论(0)
  • 2020-12-30 20:32

    I was facing the same error when my Eureka client i.e microservice trying to register herself with Eureka Server.

    Client registration eureka service failure registration failed Cannot execute request on any known server

    This error message comes because of following two possibilities.

    1) The defaultZone address is incorrect , either its misspelled or the space is missing after :.

    2) Spring security implemented on Eureka server require a valid CSRF token be sent with every request. Eureka clients will not generally possess a valid cross site request forgery (CSRF) token. So you will need to disable this requirement for the /eureka/** endpoints.

    After disabling the CSRF token with follwoing line of code my Eureka client successfully register them selves with Eureka Server.

    @EnableWebSecurity
    class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().ignoringAntMatchers("/eureka/**");
            super.configure(http);
        }
    }
    

    Also below is the link from spring docs.

    https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#_securing_the_eureka_server

    0 讨论(0)
  • 2020-12-30 20:33

    This is happening because it is trying to connect to any known server, so to stop that error, a known server is eureka server on port 8761 which is its default port, you will have to update the application.properties with following

    server.port=8761
    

    To avoid eureka from registering itself, you add this to the application.properties

    eureka.client.register-with-eureka=false
    

    Ensure that EurekaServer is enabled, for example using spring boot you write the below on the main class.

    @EnableEurekaServer
    

    Please pardon me providing solution using .properties file but that is what i work with but .yml configurations shouldn't be too different.

    0 讨论(0)
  • 2020-12-30 20:33

    Check your URL and port number of eureka server provided in "eureka.client.serviceUrl.defaultZone" property.

    0 讨论(0)
提交回复
热议问题