【问题标题】:BCryptPasswordEncoder not imported as part of spring-boot-starter-securityBCryptPasswordEncoder 未作为 spring-boot-starter-security 的一部分导入
【发布时间】:2018-09-09 22:52:36
【问题描述】:

找不到 bean BCryptPasswordEncoder 虽然我通过 maven 依赖项和 spring-boot-starter-security 导入它

我尝试使用 BCryptPasswordEncoder 进行密码散列,但是当我启动项目时出现错误:

构造函数的参数0 com.websystique.springboot.controller.RestApiController 需要一个 豆类 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' 找不到。

我正在使用 spring-boot,我只是在我的控制器中使用它,例如:

@Autowired BCryptPasswordEncoder bCryptPasswordEncoder;

【问题讨论】:

    标签: spring-boot password-encryption password-hash


    【解决方案1】:

    @Configuration 类中添加 BcryptPasswordEncoder bean。它不会自动声明。

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    

    (可选)像这样注入。

    @Autowired
    private PasswordEncoder passwordEncoder;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 2018-12-24
      • 1970-01-01
      • 2014-04-07
      • 2022-11-10
      • 2019-10-28
      相关资源
      最近更新 更多