目的
@SpringBootTest
class Springboot01ApplicationTests {
@Autowired
private RedisTemplate<Object,Object> redisTemplate;
@Test
public void redis() {
RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
Motor motor = new Motor(1234, 22, 1, 1, 1, 1, 1, 1);
redisTemplate.opsForValue().set("cwd",motor);
//Motor cwd = (Motor) redisTemplate.opsForValue().get("cwd");
//System.out.println(cwd.getTargetPosition());
}
}
使用默认的序列化器,直接使用 redisTemplate.opsForValue().set("cwd",motor);
这样的语句是会报错的,直接解析更是无从谈起。想要完成注释掉的这几个语句正常执行,需要使用新的解析器。
org.springframework.data.redis.serializer.
SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.
SerializationFailedException:
Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException:
DefaultSerializer requires a Serializable payload but received an object of type [com.example.springboot01.pojo.Motor]
Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.example