springboot启动发现PasswordEncoder无法加载问题
异常信息:
Action:
Consider defining a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' in your configuration.
2021-12-18 14:40:43.298 ERROR 15452 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@273444fe] to prepare test instance [com.zcm.dbank.user.mapper.UserMemberMapperTest@48840594]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132) ~[spring-test-5.3.2.jar:5.3.2]
主要原因是在进行初始化是没有加载到对应的bean,在启动类自主添加相应bean:
@SpringBootApplication
@MapperScan("com.zcm.dbank.user.mapper")
public class ZcmDbankUserApplication {
public static void main(String[] args) {
SpringApplication.run(ZcmDbankUserApplication.class, args);
}
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)