猿问

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

如果我正确实施了 OAuth 2.0 授权,我将尝试使用 Postman 测试它。


我正在通过邮递员发送这个期待令牌作为回报


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


MM们
浏览 256回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答