在Spring Boot应用程序中使用BCryptPasswordEncoder时,需要在配置类中声明一个bean,如下所示:
@Configuration
public class SecurityConfig {
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}
这样在使用BCryptPasswordEncoder时就可以通过@Autowired将其注入到其他类中了。