SpringCloud学习中遇到的一些bug
There was a problem with the instance info replicator
- 错误原因: 该服务尝试将自己作为客服端注册
- 解决办法: 在application.yml配置文件中,设置
# 注册Eureka服务
eureka:
client:
# Eureka服务注册中心会将自己作为客户端来尝试注册它自己,必須禁止
register-with-eureka: false
fetch-registry: false
实体类转化出错: disable SerializationFeature.FAIL_ON_EMPTY_BEANS
- 错误原因: 使用的框架是Spring Boot,处理完请求之后,返回数据之前,在POJO转化成JSON时,有些属性违背输出规则或者有些属性循环引用会造成无法输出。
- 解决办法: 在实体类上面加上注解
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
This application has no explicit mapping for /error, so you are seeing this as a fallback.
- 错误原因: 很可能是你Application启动类放的位置不对。要将Application放在最外层,也就是要包含所有子包。
- 解决办法: 将Application放在最外层,也就是要包含所有子包。
message:Request method 'POST' not supported
There was an unexpected error (type=Internal Server Error, status=500). status 405 reading UserFeignClient#getUser(User); content: {"timestamp":"2018-09-07T09:01:14.290+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/feign-get-user"}
错误原因: 该请求不会成功,只要参数是复杂对象,即使指定了是GET方法,feign依然会以POST方法进行发送请求。可能是我没找到相应的注解或使用方法错误。
解决办法:
// 该请求不会成功,只要参数是复杂对象,即使指定了是GET方法,feign依然会以POST方法进行发送请求。可能是我没找到相应的注解或使用方法错误。
@RequestMapping(method = RequestMethod.GET, value = "/feign-get-user")
public User getUser(User user); //正确用法
@RequestMapping(method = RequestMethod.GET, value = "/feign-get-user")
public User getUser(@RequestParam("id") Long id, @RequestParam("username") String username, @RequestParam("age") String age);
}
Error creating bean with name 'eurekaAutoServiceRegistration'
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
- 错误原因:
- 同一个服务重复启了;
- 或者是端口被其他应用占用了。
- 解决办法: 释放被占用的端口即可
Read timed out
- 详细描述: com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read timed out
- 错误原因: 应用刚启动,需要通过ribbon从eureka上拉取服务;需要将虚拟主机名转化为ip地址
- 解决办法: 这是比较正常的现象,只需要再次刷新就好了
解决第一次请求报超时异常的方案
- 错误原因: 网络等原因,导致请求时间过长,进而引发timeout的错误
- 解决办法:
- 默认时间是超过1秒就是超时,将其设置为5秒
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
- 禁用超时时间timeout
hystrix.command.default.execution.timeout.enabled: false
- 索性禁用feign的hystrix支持
feign.hystrix.enabled: false
- 超时的issue:https://github.com/spring-cloud/spring-cloud-netflix/issues/768
- 超时的解决方案: http://stackoverflow.com/questions/27375557/hystrix-command-fails-with-timed-out-and-no-fallback-available
- hystrix配置: https://github.com/Netflix/Hystrix/wiki/Configuration#execution.isolation.thread.timeoutInMilliseconds
Cannot execute request on any known server
- 错误详细描述: com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
- 错误原因: Peer Awareness配置
# application.yml (Two Peer Aware Eureka Servers).
---
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2/eureka/ ---
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1/eureka/
- 解决办法: 修改C:\Windows\System32\drivers\etc路径下的hosts文件,在文末加入以下内容:
127.0.0.1 peer1 peer2 peer3
com.netflix.client.ClientException: Load balancer does not have available server for client: microservice-provider-user
- 错误原因: 消费者调用服务时无服务可用
- 解决办法:
- 确定本机是否关闭防火墙
- 是否导入eureka的jar包
<!-- 注册Eureka服务 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 确定是否导入hystrix的jar包
<!-- 配置hystrix所需依赖的包 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
- 确定配置文件服务前面是否有空格

Unable to connect to Command Metric Stream
- 错误原因: 配置文件不完整
- 解决办法: Hystrix Metrics Stream 要启用Hystrix度量标准流,请在spring-boot-starter-actuator上包含依赖项,并设置management.endpoints.web.exposure.include:hystrix.stream。 这样做会将 /actuator/hystrix.stream公开为管理端点,如以下示例所示:
- pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> </dependency>- application.yml
# 配置Hystrix Metrics Stream
management:
endpoints:
web:
exposure:
include: hystrix.stream
hystrix.stream一直是ping
- 错误原因:
- 因为没有请求任何东西,所以看不到内容;
- 缺少配置监控的依赖
- 配置环境不完善
- 解决办法:
- 访问一下其他服务,比如http://localhost:9000/goods/2(自己写的一个服务)即可看到内容
- 客服端添加依赖
<!-- Actuator是SpringBoot提供的对应用系统的自省和监控的集成功能,可以查看应用配置的详细信息;
如果提示 Unable to connect to Command Metric Stream.则需要引入以下包!
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>- 完善配置环境
# 使用Hystrix Metrics Stream必备
management:
endpoints:
web:
exposure:
include: hystrix.stream
turbine.stream一直是ping
- 错误原因:
- 因为没有请求任何东西,所以看不到内容;
- 缺少配置监控的依赖
- Eureka服务注册中心未将自己作为客户端来尝试注册它自己
# 注册Eureka服务
eureka:
client:
register-with-eureka: false
fetch-registry: false- 缺少配置监控的依赖
- 解决办法:
- 访问一下其他服务,比如http://localhost:9000/goods/2(自己写的一个服务)即可看到内容
- 客服端添加依赖
<!-- Actuator是SpringBoot提供的对应用系统的自省和监控的集成功能,可以查看应用配置的详细信息;
如果提示 Unable to connect to Command Metric Stream.则需要引入以下包!
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>- Eureka服务注册中心未将自己作为客户端来尝试注册它自己
# 注册Eureka服务
eureka:
client:
# register-with-eureka: false
# fetch-registry: false- 添加配置的依赖(作为客服端的都需要配置)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Health Indicator访问无结果
- 错误原因:
- 未导入依赖包
- 版本原因导致访问方式改变了
- 解决办法:
- 导入依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>- 访问http://localhost:8030/actuator查看
{
"_links": {
"self": {
"href": "http://localhost:8030/actuator",
"templated": false
},
"health": {
"href": "http://localhost:8030/actuator/health",
"templated": false
},
"info": {
"href": "http://localhost:8030/actuator/info",
"templated": false
}
}
}- 访问http://localhost:8030/actuator/health即可
Turbine监控多个服务,配置后,出现只监控到一部分服务情况
- 错误原因:
- 配置有问题
- 解决办法:
- application.xml配置如下:
# 0、配置多个监控服务
turbine:
appConfig: microservice-consumer-goods-feign-with-hystrix,microservice-consumer-goods-ribbon-with-hystrix
clusterNameExpression: "'default'"
# 1、仅配置监控一个服务
turbine:
aggregator:
clusterConfig: MICROSERVICE-CONSUMER-GOODS-RIBBON-WITH-HYSTRIX
appConfig: microservice-consumer-goods-ribbon-with-hystrix- 各个微服务的Controller配置
每个微服务均需要加上如下注解:
//配置hystrix所需注解
@EnableCircuitBreaker
SpringCloud学习中遇到的一些bug的更多相关文章
- SpringCloud学习(二):微服务入门实战项目搭建
一.开始使用Spring Cloud实战微服务 1.SpringCloud是什么? 云计算的解决方案?不是 SpringCloud是一个在SpringBoot的基础上构建的一个快速构建分布式系统的工具 ...
- SpringCloud学习笔记(2):使用Ribbon负载均衡
简介 Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端负载均衡工具,在注册中心对Ribbon客户端进行注册后,Ribbon可以基于某种负载均衡算法,如轮询(默认 ...
- SpringCloud学习之Ribbon
一.负载均衡与Ribbon 负载均衡,在集群中是很常见的一个“名词”,顾名思义是根据一定的算法将请求分摊至对应的服务节点上,常见的算法有如下几种: 轮询法:所有请求被依次分发到每台应用服务器上,每台服 ...
- SpringCloud学习之feign
一.关于feigin feigin是一种模板化,声明式的http客户端,feign可以通过注解绑定到接口上来简化Http请求访问.当然我们也可以在创建Feign对象时定制自定义解码器(xml或者jso ...
- SpringCloud学习系列之三----- 断路器(Hystrix)和断路器监控(Dashboard)
前言 本篇主要介绍的是SpringCloud中的断路器(Hystrix)和断路器指标看板(Dashboard)的相关使用知识. SpringCloud Hystrix Hystrix 介绍 Netfl ...
- 作为一名IT从业者,你在工作和学习中,遇到哪些问题
版权声明:襄阳雷哥的版权声明 https://blog.csdn.net/FansUnion/article/details/28448975 大家都是IT从业者,遇到的问题多少与类似. 假设能把这些 ...
- SpringCloud学习系列之七 ----- Zuul路由网关的过滤器和异常处理
前言 在上篇中介绍了SpringCloud Zuul路由网关的基本使用版本,本篇则介绍基于SpringCloud(基于SpringBoot2.x,.SpringCloud Finchley版)中的路由 ...
- springCloud学习总览
写完最后一篇特意去看了看第一篇是什么时候写的---2018/11/19,到现在三个月多一点,总的来说这三个月通过<Spring 微服务实战>这本书,算是对微服务进行了一次扫盲学习. ...
- SpringCloud学习笔记(3):使用Feign实现声明式服务调用
简介 Feign是一个声明式的Web Service客户端,它简化了Web服务客户端的编写操作,相对于Ribbon+RestTemplate的方式,开发者只需通过简单的接口和注解来调用HTTP API ...
随机推荐
- BZOJ_3427_Poi2013 Bytecomputer_DP
BZOJ_3427_Poi2013 Bytecomputer_DP Description 给定一个{-1,0,1}组成的序列,你可以进行x[i]=x[i]+x[i-1]这样的操作,求最少操作次数使其 ...
- ES6知识整理(1)--let和const命令
最近准备在业余空闲时间里一边学习ES6,一边整理相关知识.只有整理过的学习才是有效的学习.也就是学习之后要使用和整理成文,才是正在的学到了... 那么现在开始 LINK START!(首先是第一讲,前 ...
- MYSQL—— 基础入门,增、删、改、查(基础篇)
首先呢,先解释一下基本的概念,心里最起码知道就ok啦!其余更多的了解,得另查看喽! (1)什么是sql? sql:指结构化查询语言,有能力访问数据库,是一种ANSI(美国国家标准话组织)的标准计算机语 ...
- OSI七层协议与TCP连接
概述 为了追求效率,我们写代码,不可能去关注底层知识,但往往到出了问题,或者性能调优.我们就会速手无策,仔细为自己查缺补漏,总结知识点. 网络协议 互联网的本质就是一系列的网络协议,让不同计算机能够互 ...
- Nginx+Keepalived 集群方案
1.Keepalived高可用软件 Keepalived软件起初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能.因此,kee ...
- 【工具篇】Selenium 学习实践(一)环境搭建
一.环境搭建 (1)初学者最佳环境: Python 2.7 + Selenium 2+ Firefox 46 (2)喜欢尝新的环境: Python 3.6 + Selenium 3+ Firefox ...
- flask下载excel
flask 应用的基本结构: htmlweb.py -- static -- templates 将 bootstrap.min.css 放到 static 文件夹下,在 templates 文件夹下 ...
- MySQL 复制 - 性能与扩展性的基石 3:常见问题及解决方案
主备复制过程中有很大可能会出现各种问题,接下来我们就讨论一些比较普遍的问题,以及当遇到这些问题时,如何解决或者预防问题发生. 1 数据损坏或丢失 问题描述:服务器崩溃.断电.磁盘损坏.内存或网络错误等 ...
- 使用MongoDB在项目中实际运用
一.MongoDB,一个数据库,我们怎么去使用它呢?我们首先了解一下什么是MongoDb 官网的介绍是:MongoDB是专为可扩展性,高性能和高可用性而设计的数据库.它可以从单服务器部署扩展到大型.复 ...
- Python进阶:设计模式之迭代器模式
在软件开发领域中,人们经常会用到这一个概念——“设计模式”(design pattern),它是一种针对软件设计的共性问题而提出的解决方案.在一本圣经级的书籍<设计模式:可复用面向对象软件的基础 ...