2014-02-23 203 views
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.

+0

確定的問題不在於你的服務器配置中忽略的屬性? –

+0

@ JohannesH.Thanks您的回覆。其他REST控制器工作正常。我認爲問題發生在Jackson試圖將對象轉換爲JSON的時候。只是我的觀點。但服務器不顯示任何錯誤。很難追查。 – waiyan

+0

您可以嘗試設置記錄器級別以跟蹤下列軟件包嗎? 「org.springframework.web.servlet.mvc」 – indybee

回答

相關問題