79499803

Date: 2025-03-11 06:21:05
Score: 1.5
Natty:
Report link
@Service("customuserdetails")
public class CustomUserDetails implements UserDetailsService {
    @Autowired
    private UserRepo userrepo;
 
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {   
        Supplier<UsernameNotFoundException> s= () -> new UsernameNotFoundException("Error finding the user");
        
        User user=userrepo.findByUsername(username).orElseThrow(s);
        return user;
    }}

This is the implementation which is working. I had to change my security beans to @configuration, and I added @repository to my repo interfaces. I also ended up changing my User class to implement UserDetails.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @configuration
  • User mentioned (0): @repository
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Fitz chivalry farseer