java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper

当前SpringBoot版本:2.0.2.RELEASE

pom.xml:


    org.springframework.boot
    spring-boot-starter-data-redis

 

 spring data redis 配置自定义redisTemplate,设置value的序列化方式为GenericJackson2JsonRedisSerializer:

@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate redisTemplate(LettuceConnectionFactory factory) {
        RedisTemplate template = new RedisTemplate<>();
        template.setConnectionFactory(factory);
        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}

直接报错说jackson的类找不着,很明显是因为我们没有配置jackson的依赖(引入 spring-boot-starter-data-redis 时官方应该配置好依赖的)

解决办法,增加依赖:



    org.springframework.boot
    spring-boot-starter-json

 

注意:

如果我们是个web项目(依赖了 spring-boot-starter-web ),这个里面会自动依赖 jackson相关的jar包:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper_第1张图片

 

 

 

 

 

你可能感兴趣的:(springboot,redis)