美文网首页Java 杂谈SpringBootJava技术分享
SpringCloud 报错Cannot execute req

SpringCloud 报错Cannot execute req

作者: 墨迹嘿嘿 | 来源:发表于2019-06-24 20:21 被阅读0次
    ![摘星族.jpg](https://img.haomeiwen.com/i15778884/b120021cd18580c6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

    上节自己学习了SpringCloud中的服务治理包含注册中心,服务提供,这次记录一下常见的错误:

    Spring Cloud Eureka配置安全验证时Client注册报错

    2019-06-24 18:43:21.800  WARN 5628 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_YYC-TEST/LAPTOP-HUEO3FR1:yyc-test: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.8.jar:1.9.8]
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.8.jar:1.9.8]
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.9.8.jar:1.9.8]
        at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.8.jar:1.9.8]
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.8.jar:1.9.8]
        at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829) ~[eureka-client-1.9.8.jar:1.9.8]
        at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) [eureka-client-1.9.8.jar:1.9.8]
        at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:101) [eureka-client-1.9.8.jar:1.9.8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_162]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_162]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_162]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_162]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]
    
    2019-06-24 18:43:21.803  WARN 5628 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator
    
    

    今天配置好SpringCloudEureka并加上安全验证时,发现客户端连接不上服务器,就在网上找答案:

    image image image

    实际上此问题应注意以下几点:

    1:由于eureka的版本过高,并且在pom文件引入了security,然后eureka高版本默认开启csrf保护,因此我们需要在eureka服务端关闭csrf校验。

    image
    package com.zhaixingzu.yyc.registry.security;
    
    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;
    
    
    /**
     * @author Herbert
     * @date 2019/06/24
     */
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) {
            try {
                http.csrf().disable()
                    .authorizeRequests()
                    .antMatchers("/actuator/**").permitAll()
                    .anyRequest()
                    .authenticated().and().httpBasic();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
    

    2:第二种

    image.png

    3:检查配置信息是否正确,确认eureka交互的地址无误


    摘星族.jpg

    相关文章

      网友评论

        本文标题:SpringCloud 报错Cannot execute req

        本文链接:https://www.haomeiwen.com/subject/lalaqctx.html