liveBook · Manning

loadUserByUsername

As explained in Spring in Action, Sixth Edition

loadUserByUsername is the UserDetailsService operation that loads security information for a specified username.

loadUserByUsername is the single UserDetailsService operation that receives a username and retrieves the matching User for authentication. A repository-backed implementation delegates to findByUsername(); it must return a user or throw UsernameNotFoundException, never null. section 5.2.2

Repository-backed lookup

Define UserRepository with findByUsername(String username), then expose a UserDetailsService bean. Its lambda passes the supplied username to the repository, returns the matching User, and throws UsernameNotFoundException when no user exists.

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains the lookup contract and exception path, but does not descend into authentication internals.
Examples
Uses a JPA UserRepository and a lambda-defined UserDetailsService bean to load Taco Cloud users.
What it assumes
Assumes a User entity and UserRepository, while demonstrating the single-method UserDetailsService contract.
What you can do after
Build a repository-backed UserDetailsService that returns users and rejects unknown usernames correctly.
How it connects
Ties UserDetailsService to UserRepository, UserDetails, and UsernameNotFoundException.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.