springcloud报错:com.netflix.discovery.shared.transport.TransportException

1.完整报错信息:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
2.问题分析:
(1)服务端报错:可能时服务端像自己注册了,需要关闭服务端向自己注册

	eureka:
  client:
    #表示是否将自己注册进EurekaServer默认为true。
    register-with-eureka: false
    #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
    fetchRegistry: false
    service-url:
      #单机版
      defaultZone: http://localhost:7001/eureka

这里需要注意一下,配置文件中idea提示会出现default-zone这种形式,也会报错改为defaultZone

(2)客户端报错:三个原因
一个可能是服务端没有跑起来
二可能defaultZone: 配置的URL有问题
三可能是服务端的端口被占用
针对第2种情况,
你需要认真检查一下 defaultZone: 的配置,和服务端的配置是否一直;
或者是Spring2.0以后默认开的安全验证,你需要手动关闭,关闭方法为添加一个配置方法。

security:
   basic:
     enabled: true
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// Configure HttpSecurity as needed (e.g. enable http basic).
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
http.csrf().disable();
//注意:为了可以使用 http://{user}:user:{password}@{host}:host:{port}/eureka/ 这种方式登录,所以必须是httpBasic,
// 如果是form方式,不能使用url格式登录
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}}

然后添加对应的@EnableWebSecurity依赖即可

org.springframework.boot
spring-boot-starter-security
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值