org.springframework.data.redis.serializer.SerializationException: Cannot deserialize;

使用redis出现如下报错

org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: 72656469
    at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:84) ~[spring-data-redis-2.6.9.jar:2.6.9]
    at com.example.redistwo.common.RedisMessageListener.onMessage(RedisMessageListener.java:23) ~[classes/:na]
    at org.springframework.data.redis.listener.RedisMessageListenerContainer.executeListener(RedisMessageListenerContainer.java:263) [spring-data-redis-2.6.9.jar:2.6.9]
    at org.springframework.data.redis.listener.RedisMessageListenerContainer.processMessage(RedisMessageListenerContainer.java:253) [spring-data-redis-2.6.9.jar:2.6.9]
    at org.springframework.data.redis.listener.RedisMessageListenerContainer.lambda$dispatchMessage$1(RedisMessageListenerContainer.java:1051) [spring-data-redis-2.6.9.jar:2.6.9]
    at java.lang.Thread.run(Thread.java:750) ~[na:1.8.0_341]
Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: 72656469
    at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:80) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:37) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:82) ~[spring-data-redis-2.6.9.jar:2.6.9]
    ... 5 common frames omitted
Caused by: java.io.StreamCorruptedException: invalid stream header: 72656469
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:943) ~[na:1.8.0_341]
    at java.io.ObjectInputStream.(ObjectInputStream.java:401) ~[na:1.8.0_341]
    at org.springframework.core.ConfigurableObjectInputStream.(ConfigurableObjectInputStream.java:65) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.ConfigurableObjectInputStream.(ConfigurableObjectInputStream.java:51) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:70) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:75) ~[spring-core-5.3.29.jar:5.3.29]
    ... 7 common frames omitted

2023-09-07 11:55:19.692  WARN 5612 --- [    container-2] o.s.d.r.l.RedisMessageListenerContainer  : Execution of message listener failed, and no ErrorHandler has been set.

org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: 72656469
    at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:84) ~[spring-data-redis-2.6.9.jar:2.6.9]
    at com.example.redistwo.common.RedisMessageListener.onMessage(RedisMessageListener.java:23) ~[classes/:na]
    at org.springframework.data.redis.listener.RedisMessageListenerContainer.executeListener(RedisMessageListenerContainer.java:263) [spring-data-redis-2.6.9.jar:2.6.9]
    at org.springframework.data.redis.listener.RedisMessageListenerContainer.processMessage(RedisMessageListenerContainer.java:253) [spring-data-redis-2.6.9.jar:2.6.9]
    at org.springframework.data.redis.listener.RedisMessageListenerContainer.lambda$dispatchMessage$1(RedisMessageListenerContainer.java:1051) [spring-data-redis-2.6.9.jar:2.6.9]
    at java.lang.Thread.run(Thread.java:750) ~[na:1.8.0_341]
Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.StreamCorruptedException: invalid stream header: 72656469
    at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:80) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:37) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:82) ~[spring-data-redis-2.6.9.jar:2.6.9]
    ... 5 common frames omitted
Caused by: java.io.StreamCorruptedException: invalid stream header: 72656469
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:943) ~[na:1.8.0_341]
    at java.io.ObjectInputStream.(ObjectInputStream.java:401) ~[na:1.8.0_341]
    at org.springframework.core.ConfigurableObjectInputStream.(ConfigurableObjectInputStream.java:65) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.ConfigurableObjectInputStream.(ConfigurableObjectInputStream.java:51) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:70) ~[spring-core-5.3.29.jar:5.3.29]
    at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:75) ~[spring-core-5.3.29.jar:5.3.29]
    ... 7 common frames omitted


Process finished with exit code 0

解决:用错了getValueSerializer(),信息messeage用了getValueSerializer(),另一个channel用getStringSerializer()就行。

你可能感兴趣的:(redis,数据库,spring,boot)