spring-security Spring Security从3.2.9到5.7.1的迁移

ezykj2lf  于 2022-11-11  发布在  Spring
关注(0)|答案(1)|浏览(239)

我正在尝试将Spring Security从3.2.9迁移到5.7.1,并将Spring框架从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>

感谢您的帮助。

vcirk6k6

vcirk6k61#

在我进行以下更改后,问题得到解决。
我更换了以下配置:

<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>

相关问题