1
我使用angularjs $ http服务发布到Spring REST端点。这是非常直接的,它按预期工作,但终点是返回状态代码500内部错误。但在服务器端,它不显示任何错误和异常。我发送邮寄请求如下Spring RESTful服务返回500内部服务器错误
$http.post('../bookmarks/add',data,{
cache:false,
headers:{'Content-Type':'application/x-www-form-urlencoded'},
transformRequest:function(data){
if(data===undefined)
return data;
return $.param(data);
},
responseType:'json'
}).success(function(data,status,headers,config){
$('.add-form').hide();
console.log(data);
callback(data,'success');
}).error(function(data,status,headers,config){
console.log(status);
if(status==500)
callback('Server error! Try again later.','error');
});
我可以发送邮寄请求。我的REST处理程序如下。它调用一个服务来坚持一个对象。
@RequestMapping(value="/add", method=RequestMethod.POST, consumes={"application/x-www-form-urlencoded","application/json", "text/plain", "*/*"})
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Bookmark saveBookmarks(@RequestParam("caption") String caption,@RequestParam("bookmarkUrl") String bookmarkUrl,
@RequestParam(value="tags",required=false) String tags,@RequestParam(value="category", required=false) String category){
System.out.println(caption+"-"+tags+"-"+category);
//calling service and persisting the object
Bookmark bookmark= bookmakService.saveBookmark(
binder.getNewBookmark(caption,bookmarkUrl, dateGen.getToday(), category, tags)
,getUserIDFromSession());
System.out.println(bookmark);
return bookmark;
}
上述处理程序按预期工作。该对象是持久的。但浏览器控制台显示500内部服务器错误,服务器不记录任何错误和异常。一切看起来很简单。我不知道客户为什么会收到500错误。我正在使用Apache Tomcat 7.
确定的问题不在于你的服务器配置中忽略的属性? –
@ JohannesH.Thanks您的回复。其他REST控制器工作正常。我认为问题发生在Jackson试图将对象转换为JSON的时候。只是我的观点。但服务器不显示任何错误。很难追查。 – waiyan
您可以尝试设置记录器级别以跟踪下列软件包吗? “org.springframework.web.servlet.mvc” – indybee