Azure Spring Cloud 是什么?
借助 Azure Spring Cloud,可以轻松地将 Spring Boot 微服务应用程序部署到 Azure,不需更改任何代码。 该服务管理 Spring Cloud 应用程序的基础结构,因此开发人员可以专注于其代码。 Azure Spring Cloud 可以通过以下方法提供生命周期管理:综合性监视和诊断、配置管理、服务发现、CI/CD 集成、蓝绿部署等。 Link: https://docs.azure.cn/zh-cn/spring-cloud/overview
问题描述
在本地运行正常的Spring Cloud项目,部署在Azure Spring Cloud服务后,在日志中,发现大量的null pointer exception
java.lang.NullPointerException: null at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426) at io.lettuce.core.protocol.CommandHandler.write(CommandHandler.java:378) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790) at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758) at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808) at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025) at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:294) at io.lettuce.core.protocol.DefaultEndpoint.channelWriteAndFlush(DefaultEndpoint.java:392) at io.lettuce.core.protocol.DefaultEndpoint.writeToChannelAndFlush(DefaultEndpoint.java:332) at io.lettuce.core.protocol.DefaultEndpoint.write(DefaultEndpoint.java:162) at io.lettuce.core.protocol.DefaultEndpoint$RetryListener.requeueCommands(DefaultEndpoint.java:1002) at io.lettuce.core.protocol.DefaultEndpoint$RetryListener.lambda$potentiallyRequeueCommands$0(DefaultEndpoint.java:989) at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98) at io.netty.util.concurrent.PromiseTask.run(PromiseTask.java:106) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
问题解决
根据在Github和stackoverflow中查看到的信息,判断这是一个和sleuth版本相关,在新的版本中,默认启用了redis配置。通过 spring.sleuth.redis.enabled=false 来关闭默认配置, Null Point Exception问题解决。
StackOverflow :
I use spring-session-data-redis to manage sessions. It will get session data from redis before every request. But it throws a NPE when get session from redis. And if I remove spring-cloud-starter-sleuth dependency, it won't happend.
springboot version: 2.3.8.RELEASE
springcloud version: Hoxton.SR10
Here is the exception information:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Answer:
I have resolved this problem. It seems that there are some bugs in this sleuth version. I compare this new version with the old version we used, the old version sleuth doesn't intercept the redis request, but this new version will. If I disable this configuration, it won't happen. I use 'spring.sleuth.redis.enabled=false' to disable redis sleuth configuration. It is enabled by default.
GitHub: https://githubmemory.com/repo/spring-cloud/spring-cloud-sleuth/issues/1992