maven Spring mvc返回对象的json格式报500

纯属个人经验勿喷!

如果在springmvc 框架中 需要发送的请求返回的是对象的json格式 ,


1、已然配置了mvc-dispatcher-servlet.xml 里配置了

<mvc:annotation-driven/>
已然配置了maven的pom.xml 里的 
jackson-databind、
ackson-core、
ackson-annotations、
代码:
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.7.4</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>2.7.4</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
  <version>2.7.4</version>
</dependency>
2、已然在方法上加了@ResponseBody
java 代码:
@ResponseBody
@RequestMapping(value = "getloginUserName", method = RequestMethod.POST)
public UserEntity getloginUserName() {
    UserEntity user = (UserEntity) request.getSession().getAttribute("user");

    return user;


}

反正该配的都配了


js请求代码

$.ajax({
    type: "post",
    url: "getloginUserName",
    data: "json=" + params,
    cache: false,
    async: false,
    dataType: "json",
    contentType: "application/json",
    timeout: 30000,
    success: function (data) {
       alert( data);
    }
});
反正该配的都配了

但是!!!!!!!!!!!

虽然java方法进入了,but tmd返回的对象 到了前段就是报错500,(具体返回信息忘记了记,真的不想在整回前面错的版本)

这个时候可以想想有可能是

com.fasterxml.jackson.core和spring的版本冲突的问题了。。。。
在出错前配置的spring版本是
<properties>
<spring.version>4.2.6.RELEASE</spring.version>
<hibernate.version>5.1.0.Final</hibernate.version>
</properties>
上网查个别说是版本问题
然后更改 com.fasterxml.jackson.core 版本从2.9 一直换到了1.x 依然爆出错误。。
 大爷的!调整了一天多。。
看到有文章给出的是spring 的4.2.5.RELEASE 配2.7.4 的com.fasterxml.jackson.core
调整后
<properties>
  <spring.version>4.2.5.RELEASE</spring.version>
  <hibernate.version>4.3.2.Final</hibernate.version>
</properties>

运行正常。
 
总结一句。。。。反正
spring 的4.2.5.RELEASE 配2.7.4 的com.fasterxml.jackson.core是可以的
至于spring 的4.2.6.RELEASE以上的 配任何版本的 的com.fasterxml.jackson.core是否有冲突 
虽然我试了本地有问题 但是 不敢妄言, 只能说  I dont know !!! 
如果有大神知道具体哪个跟哪个冲突可以分享分享
谢谢!!!





  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值