2

I send POST request

$.ajax({         
            type: "POST",  
            url: "/common/ajax/advert/",  
            data: data,
            dataType: "json",
            contentType: "application/json",
            success: function(r){}
});

to controller

@Controller
@RequestMapping(value = "/common/ajax/advert")
public class Controller {

    @RequestMapping(value="/", method=RequestMethod.POST)
    @ResponseBody
    public  Map<String,Object> adsSearch(@RequestBody Map<String,Object> data){

        Map<String,Object> result = new HashMap<String,Object>();
        List<Advert> ads =  advSrv.getAds(data);

        result.put("obj", ads);
        return result;
}

and return 404 error, but in spring 3.2 this work fine.

Controllers with RequestMethod.GET work correct in old and new version.

Please help me to fix it.

UPD.1 I tried to create a @RestController class (Spring 4.1) with RequestMethod.POST - and it did not work too.

UPD.2 In log Spring mapped this methods properly, but post request not handled (unlike get requests, they works fine).

  • Please check my answer at here http://stackoverflow.com/questions/28675298/responsebody-in-spring-mvc-4-send-string-but-does-not-send-any-other-object-to/28809303#28809303 i have the same problem and solve with this way. – erhun Apr 14 '15 at 06:02
  • Unfortunately, it did not help. Post requests still returns 404 error – Stephen1832 Apr 14 '15 at 06:30
  • How is Jackson supposed to know to which object type to map when you give `Map`? – beerbajay Apr 14 '15 at 06:51
  • In Spring 3.2 Jackson work properly with `@ResponseBody Map` – Stephen1832 Apr 14 '15 at 07:19
  • @Stephen1832If you get 404 it means page not found, there is problem about page redirection or something else. You should debug that your ResponseBody is empty which is OK before, then add messageConvertor and renew your jackson libraries. – erhun Apr 14 '15 at 08:22

1 Answers1

3

Finaly I found a problem - it was a Spring Security after upgrading to 4.0, where csrf protection enabled by default:

DEBUG: org.springframework.security.web.csrf.CsrfFilter - Invalid CSRF token found for post-request

I add support csrf protection and all work properly.