Issue
My configuration:
@Autowired
private PasswordEncoder passwordEncoder;
@Bean
public PasswordEncoder passwordEncoderBean() {
return new BCryptPasswordEncoder();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
// @Autowired
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(jwtUserDetailsService)
.passwordEncoder(passwordEncoder);
}
this code works fine. But if I remove @Autowired
from passwordEncoder
, then I must add @Autowired
on the configure
method. But this rules not apply on authenticationManagerBean()
method. Can anyone explain ?
Solution
Look at this URL https://spring.io/guides/topicals/spring-security-architecture/ It seems that you Autowire AuthenticationManagerBuilder auth as a @Bean here.
Configure(AuthenticationManagerBuilder auth) so it will work in this case and passwordEncoder is also Autowired.
Answered By - Markovitz