我试图向Spring Data Repository添加几种方法,但出现UnsatisfiedDependencyException
AppUserRepository.java
@Repository
public interface AppUserRepository extends JpaRepository<AppUser,Long>, AppUserRepositoryCustom {
}
CustomDetailsService.java
@Service("userDetailsService")
public class CustomUserDetailsService implements UserDetailsService {
@Autowired
AppUserRepository appUserRepository;
@Override
@Transactional
public UserDetails loadUserByUsername(String usernameOrEmail)
throws UsernameNotFoundException {
AppUser appUser = appUserRepository.findByUsernameOrEmail(usernameOrEmail, usernameOrEmail)
.orElseThrow(() ->
new UsernameNotFoundException("User not found with username or email : " + usernameOrEmail)
);
return UserPrincipal. create(appUser);
}
@Transactional
public UserDetails loadUserById(Long id) {
AppUser appUser = appUserRepository.findById(id).orElseThrow(
() -> new UsernameNotFoundException("User not found with id : " + id)
);
return UserPrincipal.create(appUser);
}
AppUserRepositoryCustom.java
public interface AppUserRepositoryCustom {
Optional<AppUser> findByEmail(String email);
Optional<AppUser> findByUsernameOrEmail(String username, String email);
}
AppUserRepositoryImpl.java
public class AppUserRepositoryImpl implements AppUserRepositoryCustom {
@Override
public Optional<AppUser> findByEmail(String email) {
return Optional.empty();
}
@Override
public Optional<AppUser> findByUsernameOrEmail(String username, String email) {
return Optional.empty();
}
}
但是我遇到了UnsatisfiedDependencyException
由以下原因引起:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ userDetailsService”的bean时出错:通过字段“ appUserRepository”表达的不满意的依赖关系;
怎么了?