habuma / spring-in-action-5-samples

Home for example code from Spring in Action 5.
Apache License 2.0
1.21k stars 1.04k forks source link

Chapter 4: Problem with @Autowired in SecurityConfig class #62

Open StrahinjaMarinkov opened 4 years ago

StrahinjaMarinkov commented 4 years ago

Hi everyone,

@Autowired
private UserDetailsService userDetailsService;

Error msg:

Could not autowire. There is more than one bean of 'UserDetailsService' type. Beans: inMemoryUserDetailsManager   (UserDetailsServiceAutoConfiguration.class) userRepositoryUserDetailsService   (UserRepositoryUserDetailsService.java)

I managed to resolve this by adding ("userDetailsService") to Service annotation in a UserRepositoryUserDetailsService

@Service("userDetailsService")
public class UserRepositoryUserDetailsService implements UserDetailsService

So why is this issue happening if someone can please clarify? I see that in source code as well as in this repo, that addition isn't necessary.

Thanks!

MylQl commented 4 years ago

the same to you. I feel uncomfortable to learn Spring via the book.sigh!

codecollegeza commented 4 years ago

You should work closely with the source code on github.

Regards,Arnold Graaff (CEO) Code College (Pty) Ltd

Mobile : +27 (0)83 700 2858 or +27 (0)11 803 4079 ext. 1 Web: codecollege.co.za http://www.codecollege.co.za/ Bookings: getcertified.co.za/bookings http://www.getcertified.co.za/bookings/ LinkedIn Page: linkedin.com/company/getcertified-it-training http://www.linkedin.com/company/getcertified-it-training http://t.sidekickopen23.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XYg3M2f7MW3MPwCb8pTrdFW3N1zH656dJXFf8xYJQb02?t=http%3A%2F%2Fwizpert.com%2Farnoldgetcertified&si=6664163777052672&pi=8a1e0a8d-e145-4c8d-a7c6-fffb4bd6b846Facebook : facebook.com/CodeCollegeZA Instagram : @CodeCollegeZA Twitter : @CodeCollegeZA MICT SETA Accreditation no: ACC/2018/07/0052 Address: G19 Pinewood Square, 33 Riley Road, Woodmead Ext. 12, Johannesburg, South Africa

On Thu, 27 Feb 2020 at 08:49, MylQl notifications@github.com wrote:

Well,it must be a mistake in the book. I feel uncomfortable to learn Spring via the book.sigh!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/habuma/spring-in-action-5-samples/issues/62?email_source=notifications&email_token=AEZIZRPLYPLYPTHTR2SV7ELRE5PARA5CNFSM4KVGO5N2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENDFIWY#issuecomment-591811675, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEZIZRJSBFGJSR3BXGDTXWDRE5PARANCNFSM4KVGO5NQ .

LiUzHiAn commented 4 years ago

@StrahinjaMarinkov Add @Qualifier("userRepositoryUserDetailsService") right above the @Autowired annotation. Note that the first letter u is in lowercase.

Try it.