本文介绍了无法在Spring Security中识别认证提供者用户服务引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的DAO类中,我定义了loadUserByUsername



我的班级就像

UserDAOImpl.java

  @Repository 
public class UserDAOImpl {

public UserDetails loadUserByUsername(String name)引发UsernameNotFoundException
{
//执行
}
}

在Spring-security.xml中

 <认证经理> 
< authentication-provider user-service-ref =UserDAOImpl>
< / authentication-provider>
< / authentication-manager>

但是当我运行该程序时出现错误

 创建名为'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'的bean时出错:无法在设置bean属性'userDetailsS​​ervice'时解析对bean'UserDAOImpl'的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为'UserDAOImpl'的bean 

任何人都可以帮助我如何解决这个问题?

解决方案

通常情况下,组件扫描的bean是以小写字符开头的骆驼式所以bean将作为 userDAOImpl (而不是code> UserDAOImpl )存在于应用程序上下文中。

将您的 spring-security.xml 片段更改为

 <认证经理> 
< authentication-provider user-service-ref =userDAOImpl>
< / authentication-provider>
< / authentication-manager>

希望这可以帮到你。


I am implementing spring security in my project

In my DAO class I am defining the loadUserByUsername

my class is like

UserDAOImpl.java

@Repository
public class UserDAOImpl {

public UserDetails loadUserByUsername(String name)throws UsernameNotFoundException
{
  //implementation 
}
}

In Spring-security.xml

<authentication-manager>
        <authentication-provider user-service-ref="UserDAOImpl">
      </authentication-provider>
    </authentication-manager>

but when I run the program I am getting an error

Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'UserDAOImpl' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'UserDAOImpl' is defined

Can anyone help me how do I fix this?

解决方案

Typically beans that are component scanned are camel-cased starting with a lowercase character so the bean would exist in the application context as userDAOImpl (not UserDAOImpl)

change your spring-security.xml snippet to

<authentication-manager>
    <authentication-provider user-service-ref="userDAOImpl">
  </authentication-provider>
</authentication-manager>

Hope this works for you.

这篇关于无法在Spring Security中识别认证提供者用户服务引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 01:05