簡體   English   中英

Spring Security 4.0.1請求方法'POST'不支持

[英]Spring security 4.0.1 Request method 'POST' not supported

今天早上,我正在更新項目的外部庫。 我一次做了一個庫,所以如果出了點問題,我就知道是什么原因引起的。

我將Spring Security從3.2升級到4.0.1.RELEASE后,問題開始了。 似乎我無法使用POST提交任何表單,我總是收到錯誤消息:

HTTP Status 405 - Request method 'POST' not supported

我確認我的映射是正確的並接受POST:

2015-07-19 13:03:21,916 [       Thread-1] INFO  n.RequestMappingHandlerMapping            - Mapped "{[/_/account/add],methods=[POST]}" onto public java.lang.String com..web.AccountController.add(com..web.data.Account,org.springframework.validation.BindingResult,org.springframework.ui.Model,org.springframework.web.servlet.mvc.support.RedirectAttributes,javax.servlet.http.HttpServletRequest)
2015-07-19 13:03:21,916 [       Thread-1] INFO  n.RequestMappingHandlerMapping            - Mapped "{[/_/account/add],methods=[GET]}" onto public java.lang.String com..web.AccountController.add(com..web.data.Account,org.springframework.ui.Model)

我高度懷疑這與spring-security從3.2升級到4.0.1有關,因為在3.2上一切正常。

誰知道在使用Spring Security 4.0.1時是什么原因導致“不支持請求方法'POST'”的?

糟糕,我應該更好地閱讀“新功能”文檔。 似乎在Spring Security 4.0.1中默認啟用了CSRF。 將csrf令牌添加為隱藏字段可達到以下目的:

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM