异常信息:
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();
}
}