My Spring boot app runs but says failed to start and it says the following:
Field userDetailsService in com.example.security.WebSecurityConfiguration required a bean of type 'com.example.security.UserDetailsServiceImpl' that could not be found.
The injection point has the following annotations:
@org.springframework.beans.factory.annotation.Autowired(required=true)
Consider defining a bean of type 'com.example.security.UserDetailsServiceImpl' in your configuration.
I have tried adding @Bean
and @Service
annotations in my UserDetailsServiceImpl class and adding the beanutils dependency in the pom.xml file but it still issues the same message of failing to start.
My UserDetailsServiceImpl
class:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import com.example.domain.User;
import com.example.repository.UserRepository;
public class UserDetailsServiceImpl implements UserDetailsService{
@Autowired
private UserRepository userRepo;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepo.findByUsername(username);
if (user == null) {
throw new UsernameNotFoundException("User with username: " + username + " not found");
}
return new CustomSpringUser (user);
}
}
It should say something like successfully ran Spring-Boot app.