redisson spring启动程序的notserializableexception

vh0rcniy  于 2021-06-08  发布在  Redis
关注(0)|答案(0)|浏览(1187)

我使用redisson spring boot starter 3.13.2和kotlin for cache,但出现以下异常:

java.lang.IllegalArgumentException: java.io.NotSerializableException: com.service.message.State
    at org.redisson.RedissonObject.encodeMapValue(RedissonObject.java:338)
    at org.redisson.RedissonMapCache.fastPutOperationAsync(RedissonMapCache.java:843)
    at org.redisson.RedissonMapCache.fastPutAsync(RedissonMapCache.java:746)
    at org.redisson.RedissonMapCache.fastPut(RedissonMapCache.java:720)
    at org.redisson.spring.cache.RedissonCache.put(RedissonCache.java:107)
    at org.springframework.cache.interceptor.AbstractCacheInvoker.doPut(AbstractCacheInvoker.java:87)
    at org.springframework.cache.interceptor.CacheAspectSupport$CachePutRequest.apply(CacheAspectSupport.java:820)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:429)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
    at ...
Caused by: java.io.NotSerializableException: com.service.message.State
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:272)
    at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
    at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
    at org.redisson.codec.MarshallingCodec$4.encode(MarshallingCodec.java:176)
    at org.redisson.RedissonObject.encodeMapValue(RedissonObject.java:336)
    ... 115 common frames omitted
Caused by: org.jboss.marshalling.TraceInformation: null

我的配置类是这样的:

@Configuration
@EnableCaching
class CacheConfig {
    @Bean
    fun cacheManager(client: RedissonClient): CacheManager {
        val config = org.redisson.spring.cache.CacheConfig()
        config.ttl = 10 * 60 * 1000
        return RedissonSpringCacheManager(client, mapOf("State" to config))
    }
}

我试图缓存的类型:

data class State(
    val phoneCode: String,
    val phoneNumber: String
)

这就是我试图缓存它的方式:

@CachePut(value = ["State"], key = "#id")
    fun initializeState(phoneAreaCode: String, phoneNumber: String, id: String): State {
        ...
        return State(
            phoneCode = "...",
            phoneNumber = "...",
            ...
        )
    }

编辑:我设法通过添加 JsonJacksonCodec()RedissonSpringCacheManager(client, mapOf("State" to config), JsonJacksonCodec()) 但现在我在反序列化时遇到了问题:

unable to decode data. channel: [id: 0x81736df6, L:/...], reply: ReplayingDecoderByteBuf(ridx=1704, widx=1704), command: (EVAL), params: [local value = redis.call('hget', KEYS[1], ARGV[2]); if value == false then return nil; end; local t,..., 5, ...
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: 1695]

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题