POST request in Spring MVC not work after migration from 3.2 to 4.1
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).
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.
链接地址: http://www.djcxy.com/p/48478.html上一篇: 弹簧mvc以json格式输出