Arrays类型中的方法asList(T ...)不适用于参数(Role,Role)

问题描述 投票:0回答:1

我正在尝试使用Postman测试OAuth 2.0授权,如果我已正确实现它。

我寄给朋友一个期待的令牌作为回报

http://localhost:8080/oauth/token/grant_type=password&username=user&password=user

但我在这部分代码中有错误:

@SpringBootApplication
public class KamehouseApplication {

    public static void main(String[] args) {
        SpringApplication.run(KamehouseApplication.class, args);

    }

    @Autowired
    public void configure(AuthenticationManagerBuilder auth, UserRepository repo, User user) throws Exception {
        if (repo.count() == 0)
            user = (new User("user", // username
                    "user", // password
                    Arrays.asList(new Role("USER"), new Role("ACTUATOR"))));// roles

        repo.save(user);

        auth.userDetailsService(s -> new CustomUserDetails(repo.findByUsername(s)));
    }
}

红色下划线的部分是

Arrays.asList(new Role("USER"), new Role("ACTUATOR"))));

The method asList(T...) in the type Arrays is not applicable for the arguments (Role, Role)

这是我的用户类

@Entity
@Table(name = "user")
public class User {

    @Id
    @GeneratedValue
    public int id;

    public String firstname;
    public String lastname;
    public String username;
    public String password;

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private List<Role> roles;

    public User() {
    }

    //Getters/Setters
java spring oauth-2.0
1个回答
0
投票

我已经改变了构造函数

public Role() {

}

public Role(String string) {

}

到我的Role.java文件,也添加了

public User(String username, String password, List roles) {
}

到我的User.java,现在它正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.