spingmvc 返回json数据时报错,spingmvc启动失败
严重: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at java.lang.Thread.run(Thread.java:745)
spingmvc-servlet.xml配置如下:
text/html;charset=UTF-8
application/json;charset=UTF-8
pom.xml依赖
com.fasterxml.jackson.core
jackson-databind
2.6.5
com.fasterxml.jackson.core
jackson-core
2.6.5
com.fasterxml.jackson.core
jackson-annotations
2.6.5
spring版本是4.x
controller代码如下
@Controller
@RequestMapping("/json")
public class UserController {
//用户注册
@RequestMapping(value = "/register.do")
@ResponseBody
public Map register() throws IOException {
Map map = new HashMap();
map.put("xx", "ok");
return map;
}
}
浏览器输入
http://localhost:8080/MybatisDemo/json/register.do
后台就提示启动springmvc失败,说是找不json对应的类,可是相关的依赖我都添加了啊。。
前台提示Servlet.init() for servlet springmvc threw exception,忙活半天了。。网上的方案都不能解决.
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
有没有多个版本的jackson-core???
一般加json-all一个就行了。你试着把其他的包去掉。加上这个试下。