簡體   English   中英

春季安全性沒有定義名為“ CustomAuthenticationProvider”的bean

[英]Spring security No bean named 'CustomAuthenticationProvider' is defined

我想去獲得Spring Security認證表格。 這是spring-security.xml文件的一部分

<bean id="authenticationFilter" class="com.portal.framework.web.security.CustomAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManager" />
        <property name="filterProcessesUrl" value="/login/validate" />
        <property name="usernameParameter" value="usernameOrEmail" />
        <property name="passwordParameter" value="password" />
        <property name="authenticationSuccessHandler" ref="restAuthenticationSuccessHandler" />
        <property name="authenticationFailureHandler" ref="restAuthenticationFailureHandler" />

    </bean>

    <authentication-manager alias="authenticationManager" xmlns="http://www.springframework.org/schema/security">
        <authentication-provider ref="customAuthenticationProvider" />
    </authentication-manager>

我收到錯誤:未定義名為“ customAuthenticationProvider”的Bean

Bean解析由Java配置完成,如下所示:

@Configuration
@ComponentScan(basePackages = {"com.portal"})
public class MainConfiguration {

    @Bean
    public CustomAuthenticationProvider customAuthenticationProvider() {
        return new CustomAuthenticationProvider();
    }
}

這個配置有什么問題嗎?

通過更換解決了問題

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/someXmlfile.xml</param-value>
    </context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        com.portal.configuration.IntegrationServerWebConfig
    </param-value>
</context-param>

並定義類:

@Configuration

@ImportResource({
    "classpath:/WEB-INF/mvc-dispatcher-servlet.xml",
    "classpath:/WEB-INF/spring-servlet.xml"})

@ComponentScan(basePackages = {"com.portal"})
public class IntegrationServerWebConfig {
}

您的XML配置應定義要掃描其他組件的軟件包。 您可以這樣做:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">

 <context:component-scan base-package="org.example"/>

</beans>

暫無
暫無

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

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