我似乎陷入了困境,无法弄清楚发生了什么。我目前正在尝试将用户从使用 Sha-256 加密迁移到使用 Spring 安全性的 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 还很陌生,所以我可能会错过一些非常简单的东西。
最佳答案
看起来这些字符就在那里(并且也复制到您的问题中,Firefox 奇怪地显示该行)。
如果我运行:
curl http://stackoverflow.com/questions/27544456/spring-security-cannot-find-class-daoauthenticationprovider | grep --context=2 class=\"org.springframework.security.authentication.dao.DaoAuthenticationProvider | less
我得到:
<bean id="customAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider<U+200C><U+200B>">
<property name="userDetailsService" ref="userDetailsService" />
<property name="passwordEncoder" ref="bCryptPasswordEncoder" />
所以它们肯定出现在您上面发布的内容中。尝试删除该行并按照 holmis83 的建议再次重写。
关于java - Spring security - 找不到类 DaoAuthenticationProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27544456/