当前位置: 代码迷 >> 综合 >> springcloud报错:com.netflix.discovery.shared.transport.TransportException
  详细解决方案

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

热度:76   发布时间:2024-02-10 21:12:28.0

1.完整报错信息:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server


2.问题分析:
(1)服务端报错:可能时服务端像自己注册了,需要关闭服务端向自己注册

eureka:client:fetch-registry: falseregister-with-eureka: falseservice-url:defaultZone: http://{eureka.instance.hostname}:eureka.instance.hostname:{server.port}/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
  相关解决方案