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.springboot01.pojo.Motor]
Caused by: java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.example.springboot01.pojo.Motor]
@Configuration
public class rediscConfig {
@Bean
public RedisTemplate
测试类
@SpringBootTest
class Springboot01ApplicationTests {
@Autowired
@Qualifier("MyRedisTemplate")
private RedisTemplate 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");
}
}
这样测试类中可以set一个对象,但是获取(注释语句)仍会报错。
class java.util.linkedHashMap cannot be cast to class com.example.springboot01.pojo.Motor
(java.util.linkedHashMap is in module java.base of loader 'bootstrap';
com.example.springboot01.pojo.Motor is in unnamed module of loader 'app')