nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
在公司framework中定义了springdataredis key及value的序列化方式,
public RedisTemplate<Object, Object> redisTemplate(
RedisConnectionFactory redisConnectionFactory)
throws UnknownHostException {
RedisTemplate<Object, Object> template = new RedisTemplate<Object, Object> ();
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文件
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.2</version>
<scope>runtime</scope>
</dependency>