Spring Security从3.2.9到5.7.1的迁移



我正在尝试将Spring Security从3.2.9迁移到5.7.1,Spring framework从3.2.13迁移到5.3.20。

在运行时,我得到以下错误:

没有找到默认构造函数;

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'basicAuth' defined in ServletContext resource [/WEB-INF/security.xml]: 
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.security.web.authentication.www.BasicAuthenticationFilter]: 
No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.web.authentication.www.BasicAuthenticationFilter.<init>()
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334)
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at deployment.mycompany.war//org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at deployment.mycompany.war//org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at deployment.mycompany.war//org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330)
... 52 more
下面是bean配置的代码片段:
<beans:bean id="basicAuth" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter" >
<beans:property name="authenticationManager" ref="authenticationManager"/>
<beans:property name="authenticationEntryPoint" ref="basicAuthEntryPoint" />
</beans:bean> 

尝试为authenticationEntryPoint添加构造函数初始化。还是不能用

<beans:bean id="basicAuth" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter" >
<beans:property name="authenticationManager" ref="authenticationManager"/>
<beans:property name="authenticationEntryPoint" ref="basicAuthEntryPoint" />
<beans:constructor-arg index="1" ref="basicAuthEntryPoint" />
</beans:bean> 

谢谢你的帮助。

我做了以下修改后问题解决了

我替换了以下配置:

<b:bean class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
<b:property name="authenticationManager" ref="authenticationManager"/>
<b:property name="authenticationEntryPoint" ref="entryPoint"/>
</b:bean>

与这个:

<b:bean class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
<b:constructor-arg ref="authenticationManager"/>
<b:constructor-arg ref="entryPoint"/>
</b:bean>

最新更新