Моё весеннее загрузочное приложение запускается, но говорит, что не удалось запустить, и оно говорит следующее:
Для поля userDetailsService в com.example.security.WebSecurityConfiguration требуется компонент типа com.example.security.UserDetailsServiceImpl, который не может быть найден.
Точка впрыска имеет следующие аннотации:
@org.springframework.beans.factory.annotation.Autowired(required=true)
Рассмотрите возможность определения bean-компонента типа 'com.example.security.UserDetailsServiceImpl' в вашей конфигурации.
Я попытался добавить аннотации @Bean
и @Service
в мой класс UserDetailsServiceImpl и добавить зависимость beanutils в файл pom.xml, но он по-прежнему выдает то же сообщение о невозможности запуска.
Мой UserDetailsServiceImpl
класс:
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);
}
}
Должно быть что-то вроде успешного запуска приложения Spring-Boot.