【问题标题】:Spring security - Cannot find class DaoAuthenticationProviderSpring security - 找不到类 DaoAuthenticationProvider
【发布时间】:2015-02-17 02:45:33
【问题描述】:

我似乎陷入了困境,无法弄清楚发生了什么。我目前正在尝试使用 Spring 安全性将用户从使用 Sha-256 加密迁移到 Bcyrpt。我查看了 this answer 并设置了该类,但是在 Tomcat 启动时出现以下错误:

     ERROR org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:307) - Context initialization failed
    org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class   [org.springframework.security.authentication.dao.DaoAuthenticationProvider<200c><200b>] for  bean with name 'customAuthenticationProvider' defined in file  [/var/lib/tomcat7/webapps/UKExtranet/WEB-INF/classes/META-INF/spring/applicationContext-security.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.security.authentication.dao.DaoAuthenticationProvider<200c><200b>

虽然这看起来很简单(ClassNotFoundException),但该类肯定存在,但我已经检查过,甚至让同事检查以防我发疯,他也说它在那里。

下面是我的 applicationContext-security.xml 文件的相关部分:

     <bean id='bCryptPasswordEncoder'
    class='co.uk.thehartford.life.security.passwordencoder.MigrateUsersPasswordEncoder' />

<security:authentication-manager>
    <security:authentication-provider
        user-service-ref="userDetailsService">
        <security:password-encoder ref="bCryptPasswordEncoder" />
    </security:authentication-provider>
</security:authentication-manager>


<bean id="userDetailsService" class="co.uk.thehartford.life.security.dao.ExtranetJdbcDaoImpl">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="customAuthenticationProvider"
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider‌​">
    <property name="userDetailsService" ref="userDetailsService" />
    <property name="passwordEncoder" ref="bCryptPasswordEncoder" />
</bean>

我不知道是什么导致了这个错误。谁有想法?任何帮助是极大的赞赏。谢谢,如果需要任何进一步的信息,请告诉我,我会发布我可以发布的。

我还应该指出,我对 Spring 还很陌生,所以我可能会遗漏一些非常简单的东西。

【问题讨论】:

  • &lt;200c&gt;&lt;200b&gt; 让我想知道你的配置中是否有一些垃圾字符?
  • 我也想过,但是在 application-securityContext 中,类名后面没有空格,所以如果那里有垃圾字符或被插入,我不知道如何检查
  • 您是否尝试删除并重写该特定行?
  • 现在想起来,我只是复制粘贴,没有删改,我现在试试。
  • 这正是holmis83的问题,感谢您的帮助!

标签: java spring spring-mvc spring-security


【解决方案1】:

看起来字符在那里(并且也复制到您的问题中,Firefox 奇怪地显示该行)。

如果我跑:

 curl http://stackoverflow.com/questions/27544456/spring-security-cannot-find-class-daoauthenticationprovider  | grep --context=2 class=\"org.springframework.security.authentication.dao.DaoAuthenticationProvider | less

我明白了:

&lt;bean id="customAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider<U+200C><U+200B>"&gt;
&lt;property name="userDetailsService" ref="userDetailsService" /&gt;
&lt;property name="passwordEncoder" ref="bCryptPasswordEncoder" /&gt;

所以它们肯定出现在您上面发布的内容中。尝试删除该行并按照 holmis83 的建议重新重写。

【讨论】:

  • 这正是问题所在!一整天都浪费在这样的事情上!感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2015-12-01
  • 2013-11-27
  • 2014-05-09
  • 2021-05-31
  • 2018-08-13
  • 2015-11-17
  • 2017-02-14
相关资源
最近更新 更多