提问人:Sebuhi Huseynov 提问时间:5/27/2023 最后编辑:Brian Tompsett - 汤莱恩Sebuhi Huseynov 更新时间:5/29/2023 访问量:192
springframework.data.redis.serializer.SerializationException:无法序列化
springframework.data.redis.serializer.SerializationException: Cannot serialize
问:
我在使用 Redis Cash 时遇到了问题。当我尝试调用方法时,我得到:getById
Action.handleValidationException.error 验证异常:org.springframework.data.redis.serializer.SerializationException:
无法序列化
我的每个实体都扩展了.所有 DTO 实体都是记录。每个实体都实现 .
如何解决这个问题?BaseEntity
Serializable
@Getter
@Setter
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
@Serial
private static final long serialVersionUID = 0;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;
@CreationTimestamp
@Column(updatable = false)
private LocalDateTime createdAt;
@UpdateTimestamp
private LocalDateTime updatedAt;
}
@Service
@RequiredArgsConstructor
@Slf4j
@EnableCaching
public class UniversityServiceImpl implements UniversityService {
private final UniversityRepository universityRepository;
private final UniversityMapper universityMapper;
@Override
@Cacheable(value = "getById",key = "#id")
public UniversityResponseDTO getById(Long id, String lang) {
log.info("Action.getById.start");
University university = universityRepository.getById(id);
log.info("Action.getById.end");
return universityMapper.toUniversityResponseDTO(university, lang);
}
}
@Configuration
@EnableRedisRepositories
public class RedisConfiguration {
@Value("${redis.host}")
private String host;
@Bean
public JedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, 6379);
return new JedisConnectionFactory(config);
}
@Bean
public RedisTemplate<?, ?> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
}
答: 暂无答案
评论