This is the error that appears when I try to create a new user
"message": "Cannot invoke \"org.springframework.security.crypto.password.PasswordEncoder.encode(java.lang.CharSequence)\" because \"this.passwordEncoder\" is null", "path": "/auth/nuevo"
this is my code MainSecurity:
`
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class MainSecurity {
@Autowired
UserDetailsImpl userDetailsServiceImpl;
@Autowired
JwtEntryPoint jwtEntryPoint;
@Bean
public JwtTokenFilter jwtTokenFilter() {
return new JwtTokenFilter();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsServiceImpl).passwordEncoder(passwordEncoder());
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration)
throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.exceptionHandling().authenticationEntryPoint(jwtEntryPoint).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeHttpRequests()
.requestMatchers("/**").permitAll()
.anyRequest().authenticated();
http
.addFilterBefore(jwtTokenFilter()
, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
}
`
I can't find how to solve the error.I am using spring-boot version 3.0.6, if you need more information, please let me know.