问题描述:
NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
原因分析:
在确定maven依赖中对应的版本对应和代码正确的情况下仍然出现NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper报错,不能访问对应的映射地址
<dependency >
<groupId> com.fasterxml.jackson.core</groupId>
<artifactId> jackson-core</artifactId>
<version>2.9.0</version>
</dependency>
<dependency >
<groupId> com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<dependency >
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId> jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
@RequestMapping("quick")
@ResponseBody
public String save() throws Exception {
User user=new User();
user.setUsername("lisi");
user.setAge(16);
//使用json转换工具将对象转换成为json字符串进行返回
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(user);
return json;
}
解决方案:
将本项目的Artifacts删除,重新添加,再到Tomcat中重新添加一次,就ok了;如果还不行,重启IDEA,再不行,重启电脑,人常说重启能解决99%的问题。
到这,问题解决!