redis value序列化报错 找不到nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper

nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper

在公司framework中定义了springdataredis key及value的序列化方式,

        public RedisTemplate redisTemplate(
                RedisConnectionFactory redisConnectionFactory)
                throws UnknownHostException {
            RedisTemplate template = new RedisTemplate ();
            template.setConnectionFactory ( redisConnectionFactory );
            template.setKeySerializer ( myStringSerializer() );
            template.setHashKeySerializer ( myStringSerializer () );
            // 使用Jackson2JsonRedisSerialize 替换默认序列化
            Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.setVisibility( PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
            objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
            jackson2JsonRedisSerializer.setObjectMapper(objectMapper);

            template.setValueSerializer ( jackson2JsonRedisSerializer );
            template.setHashValueSerializer ( jackson2JsonRedisSerializer );
            template.afterPropertiesSet ();
            return template;
        }

测试类运行OK ,可以修改成功

但是其他项目集成framework,项目启动时报错 找不到Jackson相关jar包。
开始查找问题,开始一直以为是jar包冲突或者版本不对,尝试了 很多次 都不能解决问题。
后面直接去解压已经打好的war包,进入lib目录 查找jackson jar版本时发现 maven并没有把jackson 相关jar包加入其中,后面更改pom文件

        
            com.fasterxml.jackson.core
            jackson-core
            2.8.2
            runtime
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.8.0
            runtime
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.8.2
            runtime
        

你可能感兴趣的:(redis value序列化报错 找不到nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper)