将@Cacheable批注添加到我的rest方法之一后,出现以下错误:
"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() {...
和DevicesFloorDTO如下所示:
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之后会发生错误。我进行了很多搜索,但仍然不知道是什么原因导致此错误,以及如何解决此问题。任何评论可能会有所帮助。解冻很多!