用户实体-找不到符号

时间:2019-06-27 10:44:27

标签: java spring maven intellij-idea oauth-2.0

我正在尝试使用OAuth设置用户和身份验证。 我所有的源代码都在这里:https://github.com/Incybro/Spring-Blog

我在Intellij IDEA中安装了lombok插件,重新启动了IDE,但存在一些错误:

C:\Users\Admin\Desktop\Spring-Blog\src\main\java\com\github\Spring\Blog\config\ResourceServerConfig.java
Error:(12, 12) java: class com.github.Spring.Blog.config.ResourceServerConfig is already defined in package com.github.Spring.Blog.config
C:\Users\Admin\Desktop\Spring-Blog\src\main\java\com\github\Spring\Blog\services\UserService.java
Error:(20, 53) java: cannot find symbol
  symbol:   method getPassword()
  location: variable user of type com.github.Spring.Blog.entities.User
C:\Users\Admin\Desktop\Spring-Blog\src\main\java\com\github\Spring\Blog\SpringBlogApplication.java
Error:(27, 55) java: constructor Role in class com.github.Spring.Blog.entities.Role cannot be applied to given types;
  required: no arguments
  found: java.lang.String
  reason: actual and formal argument lists differ in length
Error:(27, 73) java: constructor Role in class com.github.Spring.Blog.entities.Role cannot be applied to given types;
  required: no arguments
  found: java.lang.String
  reason: actual and formal argument lists differ in length
C:\Users\Admin\Desktop\Spring-Blog\src\main\java\com\github\Spring\Blog\services\CustomUserDetailsService.java
Error:(29, 26) java: cannot find symbol
  symbol:   method getUsername()
  location: variable u of type com.github.Spring.Blog.entities.User
Error:(30, 26) java: cannot find symbol
  symbol:   method getPassword()
  location: variable u of type com.github.Spring.Blog.entities.User
Error:(31, 26) java: cannot find symbol
  symbol:   method isActive()
  location: variable u of type com.github.Spring.Blog.entities.User
Error:(32, 26) java: cannot find symbol
  symbol:   method isActive()
  location: variable u of type com.github.Spring.Blog.entities.User
Error:(33, 26) java: cannot find symbol
  symbol:   method isActive()
  location: variable u of type com.github.Spring.Blog.entities.User
Error:(34, 26) java: cannot find symbol
  symbol:   method isActive()
  location: variable u of type com.github.Spring.Blog.entities.User
Error:(36, 34) java: cannot find symbol
  symbol:   method getRoles()
  location: variable u of type com.github.Spring.Blog.entities.User

在这行中:

public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
public void save(User user){
    user.setPassword(passwordEncoder.encode(user.getPassword()));
    repo.save(user);
}
@Bean
public CommandLineRunner setupDefaultUser(UserService service) {
    return args -> {
        service.save(new User(
                "user", //username
                "user", //password
                Arrays.asList(new Role("USER"), new Role("ACTUATOR")),//roles
                true//Active
        ));
    };
}
  @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return repo
                .findByUsername(username)
                .map(u -> new org.springframework.security.core.userdetails.User(
                        u.getUsername(),
                        u.getPassword(),
                        u.isActive(),
                        u.isActive(),
                        u.isActive(),
                        u.isActive(),
                        AuthorityUtils.createAuthorityList(
                                u.getRoles()
                                        .stream()
                                        .map(r -> "ROLE_" + r.getName().toUpperCase())
                                        .collect(Collectors.toList())
                                        .toArray(new String[]{}))))
                .orElseThrow(() -> new UsernameNotFoundException("No user with "
                        + "the name " + username + "was found in the database"));
    }

}

所有内容均未标记为红色。我无法启动我的应用程序。源代码是从https://www.youtube.com/watch?v=IOgCMtYMr2Q&list=PLcoE64orFoVsxAam_BuQBrNC8IO238SwH&index=2

复制的

1 个答案:

答案 0 :(得分:2)

修复您的ResourceServerConfig类。使用下面的代码

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

代替

public class ResourceServerConfig {

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {