0

I have recently moved a project from spring 3 to spring 4 and my restful controllers don't work anymore.

My methods look like this:

@RequestMapping(value = "/app/barcode/generate", method = RequestMethod.POST)
@ResponseBody
public String doStuff(@RequestBody MyDTO dto) {
    return "Boo";
}

but when I call them from javascript I get this error:

Handler execution resulted in exception: Content type 'application/json' not supported

If I remove @RequestBody the param is always null.

My ajax calls are configured like this

$.ajax({
        url : url,
        type : 'POST',
        cache : false,
        contentType: "application/json",
        headers : {
            "Cache-Control" : "no-cache,no-store,must-revalidate",
            "Pragma" : "no-cache",
            "Expires" : "-1",
            "X-Content-Type-Options" : "NOSNIFF",
            "X-XSS-Protection" : "1",
            "X-Frame-Options" : "SAMEORIGIN"
        },
        dataType: 'json',
        data : requestData,
        beforeSend : function(xhr) {
            var token = $("meta[name='_csrf']").attr("content");
            var header = $("meta[name='_csrf_header']").attr("content");
            xhr.setRequestHeader(header, token);
        }
    });

This all worked completely fine in spring 3. The main difference is that I am now using Java Config.

SME
  • 281
  • 2
  • 3
  • 7

0 Answers0