java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
程序员文章站
2022-07-14 08:51:52
...
当前SpringBoot版本:2.0.2.RELEASE
pom.xml:
<!--redis client:lettuce--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
spring data redis 配置自定义redisTemplate,设置value的序列化方式为GenericJackson2JsonRedisSerializer:
@Configuration public class RedisConfig { @Bean public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory factory) { RedisTemplate<String, Object> 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 时官方应该配置好依赖的)
解决办法,增加依赖:
<!-- jackson --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> </dependency>
注意:
如果我们是个web项目(依赖了 spring-boot-starter-web ),这个里面会自动依赖 jackson相关的jar包:
推荐阅读
-
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
-
JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonM
-
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
-
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
-
JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonM
-
nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
-
SpringBoot整合JPA做查询时报的一个错com.fasterxml.jackson.databind.exc.InvalidDefinitionException