Spring MVC 名为“请求数据值处理器”的Bean必须为[org.springframework.web.servlet.support.请求数据值处理器]类型

rbpvctlc  于 2023-03-03  发布在  Spring
关注(0)|答案(2)|浏览(129)
Servlet.service() for servlet [springmvc] in context with path [] 
threw exception [Request processing failed; nested exception is 
org.springframework.beans.factory.BeanNotOfRequiredTypeExcepti
on: Bean named 'requestDataValueProcessor' must be of type [org.springframework.web.servlet.support.RequestDataValueProcessor], 
but was actually of type [org.springframework.security.web.servlet.suppo
rt.csrf.CsrfRequestDataValueProcessor]] 
with root cause
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 
'requestDataValueProcessor' must be of type 
[org.springframework.web.servlet.support.RequestDataValueProcessor], but was actually of type 
[org.springframework.security.web.servlet.support.csrf.CsrfRequestDataValueProcessor]

我收到此错误。

sc4hvdpw

sc4hvdpw1#

此问题是在从Spring Security 3.x升级到4.x时导致的。在Spring Security 4中,CSRF现在默认启用。
将以下内容添加到登录页面

<csrf disabled="true"/>

Spring Security 3到4迁移指南http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-xml.html#m3to4-xmlnamespace-csrf

wwodge7n

wwodge7n2#

我可以通过将CsrfRequestDataValueProcessor的内容克隆到我自己的类中来解决这个问题。这听起来像是类加载器的问题,但这是一个快速修复。
然后将其添加到安全配置中。

<beans:bean name="requestDataValueProcessor"
        class="com.pa.web.internal2.tools.spring.csrf.ClonedCsrfRequestDataValueProcessor" />

相关问题