欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

spring boot redis 序列化报错 as a subtype of [simple type, class java.lang.Object]: no such class found

程序员文章站 2022-06-28 16:13:59
redis 原配置 @Bean public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){ //配置redisTemplate RedisTemplate redisTemplate = new RedisTemplate();...

redis 原配置

    @Bean
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
        //配置redisTemplate
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        RedisSerializer stringSerializer = new StringRedisSerializer();

		......
		
        return redisTemplate;
    }

异常信息

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Could not resolve type id 'com.xxx.BeanVo' as a subtype of [simple type, class java.lang.Object]: no such class found
  • 关键信息 as a subtype of [simple type, class java.lang.Object]: no such class found

解决后的配置

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        //配置redisTemplate
        RedisTemplate redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        RedisSerializer stringSerializer = new StringRedisSerializer();

		......
		
        return redisTemplate;
    }
  • 其实我只是把创建RedisTemplate对象时指定的泛型去掉了
  • 到此问题解决!

本文地址:https://blog.csdn.net/wency935486/article/details/112008465