2 回答
TA贡献1785条经验 获得超8个赞
你有一个,因为你通过在定义它的 bean中BeanCurrentlyInCreationException自动装配 bean 来创建 bean 之间的循环依赖关系。BCryptPasswordEncoderSecurityConfig
这是您必须删除的内容:
@Autowired
private BCryptPasswordEncoder passwordEncoder;
相反,您应该使用方法引用来引用BCryptPasswordEncoder:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowire
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService)
.passwordEncoder(bCryptPasswordEncoder());
}
}
或者在不扩展的BCryptPasswordEncoder单独类中声明bean 。@ConfigurationWebSecurityConfigurerAdapter
TA贡献1982条经验 获得超2个赞
您可以直接注入 UserDetailsServiceImpl :
@Autowired private UserDetailsServiceImpl userDetailsService;
添加回答
举报