我是 Spring Boot 新手,正在尝试使用 JPA 存储库。我试图找出 spring SimpleJpaRepository 类在运行时保存数据库表的位置以执行进一步的检索操作。我有以下服务类来根据用户名检索用户。在 Eclipse 中,我尝试检查第 9 行的 userRepository 但我不知道在哪里可以找到 spring 从数据库表中获取的值。我知道 User
类将包含我想要查找的详细信息,但我想查看这些详细信息在 userRepository
中的位置。任何帮助深表感谢。
package com.hellokoding.auth.service;
@Service
public class UserDetailsServiceImpl implements UserDetailsService{
@Autowired
private UserRepository userRepository;
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(String username) {
User user = userRepository.findByUsername(username); //line 9
if (user == null) throw new UsernameNotFoundException(username);
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
for (Role role : user.getRoles()){
grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
}
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities);
}
}
最佳答案
您正在查看错误的库。 Spring Data JPA 只是 JPA(很可能是 Hibernate)的前端。您想要在其中查找 EntityManager
接口(interface)的实现。
关于java - 在简单的 JPA 存储库中哪里可以找到数据库表对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61444878/