Skip to content
Advertisement

Spring Security UserDetailsService must be set Error

Just i dont understand, why customUserDetailsService doesn’t autowire There are 2 classes i use

JavaScript

=================

JavaScript

And there is stackTrace

JavaScript

Please explain me, how it’s possible. These classes have the same package, i included this package @ComponentScan annotation. And spring still complains that he cant find @Service Component. There is something easy, but i cant get it. Please help.

Advertisement

Answer

I think you don’t have to mark customUserDetailService with @Service annotation. Besides, the db operation and transaction shoule be done in userService to distinguish the duty of each layer. Refactor CustomUserDetailsService like this:

JavaScript

And according to Spring Security refence:

5.6.5 UserDetailsService

You can define custom authentication by exposing a custom UserDetailsService as a bean. For example, the following will customize authentication assuming that SpringDataUserDetailsService implements UserDetailsService:

[Note] This is only used if the AuthenticationManagerBuilder has not been populated and no AuthenticationProviderBean is defined.

So remove the bean DaoAuthenticationProvider in SpringSecurityConfig and:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement