我正在编写一个Java Spring Boot Web App,我在下面的类中遇到的问题只发生在一个地方。
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import bcoreHW.model.SiteUser;
import bcoreHW.model.UserRepo;
@Service
public class UserService implements UserDetailsService {
@Autowired
private UserRepo userRepo;
// likely unnecessary
public void register(SiteUser user) {
userRepo.save(user);
}
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
SiteUser user = userRepo.findByUsername(username);
if (user == null) {
return null;
}
List<GrantedAuthority> auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER");
String password = user.getPassword();
return new User(username, password, auth);
}
}
在loadUserByUsername()方法中,出现了以下错误。"The method loadUserByUsername(String)of type UserService must override a superclass method",它说我可以通过删除@Override注解来消除这个错误,但我不想这么做。这是整个项目中唯一出现这种情况的地方,其他的@Override注解也是如此,而且我也有最新的JRE。所以我不知道问题出在哪里。任何帮助都将被感激。谢谢!我正在写一个Java Spring Boot的项目。