java - springmvc配置json时报错Error creating bean
问题描述
spingmvc 返回json数据时报错,spingmvc启动失败
严重: StandardWrapper.Throwableorg.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配置如下:
<mvc:annotation-driven><mvc:message-converters> <beanclass='org.springframework.http.converter.ResourceHttpMessageConverter'> </bean> <beanclass='org.springframework.http.converter.json.MappingJackson2HttpMessageConverter'><property name='supportedMediaTypes'> <list><value>text/html;charset=UTF-8</value><value>application/json;charset=UTF-8</value> </list></property> </bean></mvc:message-converters> </mvc:annotation-driven>
pom.xml依赖
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.6.5</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.6.5</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.6.5</version></dependency>
spring版本是4.xcontroller代码如下
@Controller@RequestMapping('/json')public class UserController {//用户注册 @RequestMapping(value = '/register.do') @ResponseBody public Map<String,Object> register() throws IOException { Map<String,Object> map = new HashMap<String, Object>();map.put('xx', 'ok');return map; }}
浏览器输入
http://localhost:8080/MybatisDemo/json/register.do
后台就提示启动springmvc失败,说是找不json对应的类,可是相关的依赖我都添加了啊。。前台提示Servlet.init() for servlet springmvc threw exception,忙活半天了。。网上的方案都不能解决.
问题解答
回答1:有没有多个版本的jackson-core???
回答2:一般加json-all一个就行了。你试着把其他的包去掉。加上这个试下。
相关文章:
1. css3动画 - 实现css3推倒动画2. android - 求 360浏览器 百度浏览器 搜狗浏览器的最新启动类名3. html按键开关如何提交我想需要的值到数据库4. html5 - HTML代码中的文字乱码是怎么回事?5. javascript - 微信小程序 wx.downloadFile下载文件大小有限制吗6. css - 前端flex布局嵌套内层的布局不起作用?7. css - ul ol前边的标记如何调整样式呢8. javascript - 如何通过参数获取Object的子节点?9. css3 - css字体样式加填充色而不是背景色10. python3.5 urllib.parse.unquote 乱码