【发布时间】:2023-04-07 10:54:02
【问题描述】:
将@Cacheable 注释添加到我的一种休息方法后出现以下错误:
"status": 500,
"error": "Internal Server Error",
"message": "class java.util.ArrayList cannot be cast to class java.util.Map (java.util.ArrayList and java.util.Map are in module java.base of loader 'bootstrap')",
方法声明为:
@Cacheable("loadDevicesFloors")
@GetMapping("/floors/all-devices")
public Map<String, DevicesFloorDTO> loadDevicesFloors() {...
DeviceFloorDTO 如下所示:
public class DevicesFloorDTO implements Serializable {
private final List<DeviceDTO> deviceDTOs;
private final String floorName;
private final Integer floorIndex;
public DevicesFloorDTO(List<DeviceDTO> devicesDtos, String floorName, Integer floorIndex) {
this.deviceDTOs = devicesDtos;
this.floorName = floorName;
this.floorIndex = floorIndex;
}...
另外我的@Bean redisTemplate 方法实现:
@Bean
JedisConnectionFactory jedisConnectionFactory() {
JedisConnectionFactory jedisConFactory
= new JedisConnectionFactory();
jedisConFactory.setHostName(redisHost);
jedisConFactory.setPort(redisPort);
jedisConFactory.setPassword(redisPassword);
return jedisConFactory;
}
@Bean
public RedisTemplate<?, ?> redisTemplate() {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
有人知道这个实现有什么问题吗?如果没有@Cacheable,它会按预期工作,但是在添加@Cacheable 之后会发生错误。我搜索了很多,但仍然不知道导致此错误的原因以及如何解决此问题。任何评论都可能会有所帮助。非常感谢!
【问题讨论】:
-
你能用这个命令从redis中取出值吗:
redis-cli GET '<key>'
标签: java spring-boot serialization redis jedis