Spring Cloud 开发微服务踩过的一个坑

材料:

Spring Cloud: Finchley.SR2
Spring Boot: 2.0.6 Realse

问题

采用H2 dababase作为微服务的嵌入式数据库,用hystrix进行监控微服务的运行情况。未使用hystrix之前可查询数据库,使用之后无法进行查询,提示错误如下。

"error":"Internal Server Error","message":"Could not write JSON: could not initialize proxy [com.example.demo.entity.User#1] - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy [com.example.demo.entity.User#1] - no Session (through reference chain: com.example.demo.entity.User_$$_jvst589_0[\"username\"]

错误重点在于no session。查询spring cloud refrence中13.2节,可采用三种方式解决问题,一是对修改@HystrixCommand的隔离属性为SEMAPHORE;二是对用该注解的方法加上@SessionScope或@RequestScope注解;三是在application.yml配置文件中增加hystrix.shareSecurityContext,设置为true。经过测试,第一种有效,其他两种无效,原因未知,写于此处,日后思考。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值