PacktPublishing / Full-Stack-Development-with-Spring-Boot-3-and-React-Fourth-Edition

89 stars 70 forks source link

Missing `@Autowired` annotation on the `configureGlobal` method #8

Closed Zhaoyu-Qu closed 9 months ago

Zhaoyu-Qu commented 9 months ago

I think the configureGlobal method in the SecurityConfig class needs an @Autowired annotation. The code presented in the book still runs, only because the framework is smart enough to adopt the only PasswordEncoder bean available. The configureGlobal method itself without an @Autowired annotation doesn't get executed or do anything at all.

Below is the amended code:

@Configuration @EnableWebSecurity public class SecurityConfig { ...

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}

...

}

juhahinkula commented 9 months ago

Thanks for raising an issue. That is correct.