次のクラスを作成します@Bean
。
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
それから他のクラスで使いたいのですBean
が、が初期化されていないと言われているので仕方がありません。
クラス:
@Configuration
@ComponentScan(basePackages = "com.inventory")
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("databaseUsersDetailsService")
private UserDetailsService userDetailsService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
そしてここで私はそれを使いたいです:
@Service
public class SessionService {
private final UserDetailsService userDetailsService;
private final BCryptPasswordEncoder encoder;
private final AuthenticationManager authenticationManager;
@Autowired
public SessionService(UserDetailsService userDetailsService, BCryptPasswordEncoder encoder, AuthenticationManager authenticationManager) {
this.userDetailsService = userDetailsService;
this.encoder = encoder;
this.authenticationManager = authenticationManager;
}
コンストラクターでは、が原因で使用できないと言われていますno beans BCryptPasswordEncoder was found
。
誰かがここで何が悪いのか考えていますか?私はを使用していSpring Boot
ます。
BCryptPasswordEncoder
Springコンテキスト内にインスタンスはありません。実際には、BeanをそのPasswordEncoder
タイプに登録しているので、そのタイプのオブジェクトを正確に注入する必要があります。
の実装PasswordEncoder
が選択されているかどうかは関係ありません。Beanの登録時に宣言したタイプも関係あります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加