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

redis 原配置

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        //配置redisTemplate
        RedisTemplate redisTemplate = new RedisTemplate();
        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对象时指定的泛型去掉了
  • 到此问题解决!

你可能感兴趣的:(java,spring,boot,spring,mvc,java,spring,spring,boot,redis)