目前我正在尝试将microservice sample转换为Spring 5反应堆栈,但是在使用Redis(通过Spring Data Redis存储会话)和Cassandra(通过Spring Data Cassandra的用户数据)创建简单的auth服务时。
新的反应堆栈的完整来源是here(WIP)。
在模拟环境中运行Spring Boot Test时,AuthServiceApplicationTests效果很好。
但IntegrationTests在运行@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
时出现异常失败。
异常信息显示:
org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR no such key
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisConnection.lambda$translateException$0(LettuceReactiveRedisConnection.java:267) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at reactor.core.publisher.Flux.lambda$onErrorMap$23(Flux.java:5170) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:88) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onError(MonoFlatMapMany.java:243) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:120) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:120) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:87) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at io.lettuce.core.RedisPublisher$State.onError(RedisPublisher.java:655) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.RedisPublisher$RedisSubscription.onError(RedisPublisher.java:313) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.RedisPublisher$SubscriptionCommand.onError(RedisPublisher.java:767) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.RedisPublisher$SubscriptionCommand.complete(RedisPublisher.java:703) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:558) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:511) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:138) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[netty-common-4.1.17.Final.jar:4.1.17.Final]
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138) ~[netty-common-4.1.17.Final.jar:4.1.17.Final]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_152]
Caused by: io.lettuce.core.RedisCommandExecutionException: ERR no such key
... 26 common frames omitted
我在this simple sample中使用了类似的解决方案来尝试Spring Session 2和Spring Security 5中的新反应功能。不同之处在于此示例中我使用MapReactiveWebSessionRepository
而不是redis特定的ReactiveWebSessionRepository。
更新了,在我的代码中将Spring Session更新为2.0.0.RELEASE,它按预期工作。
答案 0 :(得分:2)
看起来像是Spring Session' ReactiveRedisOperationsSessionRepository
中的错误。我提交了一张票,issue #954来跟踪进一步的进展。
答案 1 :(得分:1)
这确实是Spring Session的ReactiveRedisOperationsSessionRepository
(影响2.0.0.RC2
里程碑版本)的错误,是由于更改会话ID的不当处理造成的。
截至撰写此评论时,该问题已在master
中得到修复,并且将在即将到来的春季会话2.0.0.RELEASE
中提供,目前为scheduled for January 9th。
作为临时解决方法,直到2.0.0.RELEASE
结束,您可以避免在您的反应安全配置中使用WebSessionServerSecurityContextRepository
作为安全上下文存储库,并将Spring Security默认为NoOpServerSecurityContextRepository
。< / p>