step1.下载jar
浏览器打开https://github.com/redisson/redisson/tree/master/redisson-tomcat 下载redisson-all-3.8.2.jar和redisson-tomcat-8-3.8.2.jar
step2.将jar拷贝至TOMCAT_BASE/lib
step3.在TOMCAT_BASE/conf目录创建redisson.conf配置文件,文件内容如下:
{
"singleServerConfig":{
"idleConnectionTimeout":10000,
"pingTimeout":1000,
"connectTimeout":10000,
"timeout":3000,
"retryAttempts":3,
"retryInterval":1500,
"password":"yourpwd",
"subscriptionsPerConnection":5,
"clientName":null,
"address": "redis://host:ip",
"subscriptionConnectionMinimumIdleSize":1,
"subscriptionConnectionPoolSize":50,
"connectionMinimumIdleSize":32,
"connectionPoolSize":64,
"database":5,
"dnsMonitoringInterval":5000
},
"threads":0,
"nettyThreads":0,
"codec":{
"class":"org.redisson.codec.JsonJacksonCodec"
},
"transportMode":"NIO"
}
step4.修改TOMCAT_BASE/conf/context.xml添加如下配置
configPath="${catalina.base}/conf/redisson.conf" readMode="REDIS" updateMode="DEFAULT"/>
step5.重启tomcat后就可以看到redis里有redisson为key的session缓存数据了
遇到的问题&解决方案
再结合我们的CAS(单点登录),验证ST生成Session并将session保存至redis时报错如下:
Type Exception Report
Message Unexpected exception while processing command
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.redisson.client.RedisException: Unexpected exception while processing command
org.redisson.command.CommandAsyncService.convertException(CommandAsyncService.java:378)
org.redisson.command.CommandAsyncService.get(CommandAsyncService.java:182)
org.redisson.RedissonObject.get(RedissonObject.java:76)
org.redisson.RedissonMap.get(RedissonMap.java:253)
org.redisson.tomcat.RedissonSession.getAttribute(RedissonSession.java:77)
org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:103)
com.gysoft.sso.filter.CustomAuthenticationFilter.doFilter(CustomAuthenticationFilter.java:78)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263)
com.gysoft.sso.filter.SessionTimeOutFilter.doFilter(SessionTimeOutFilter.java:53)
org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:97)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
com.gysoft.utils.util.cros.CorsFilter.doFilter(CorsFilter.java:104)
Root Cause
com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 913]
com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
com.fasterxml.jackson.databind.DeserializationContext.missingTypeIdException(DeserializationContext.java:1638)
com.fasterxml.jackson.databind.DeserializationContext.handleMissingTypeId(DeserializationContext.java:1217)
com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._handleMissingTypeId(TypeDeserializerBase.java:300)
com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedUsingDefaultImpl(AsPropertyTypeDeserializer.java:164)
com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:105)
com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromAny(AsPropertyTypeDeserializer.java:193)
com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserializeWithType(UntypedObjectDeserializer.java:712)
com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68)
com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
org.redisson.codec.JsonJacksonCodec$2.decode(JsonJacksonCodec.java:92)
org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:349)
org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:128)
org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:108)
io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)
io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
java.lang.Thread.run(Thread.java:748)
更改redissson.conf如下配置
"class":"org.redisson.codec.JsonJacksonCodec"->"class":"org.redisson.codec.SerializationCodec"
重启tomcat问题解决。
遇到的问题&解决方案:https://github.com/redisson/redisson/issues/1806