SpringBoot报错-role should not start with ‘ROLE_’ since it is automatically inserted. Got ‘ROLE_USER’
本文引用-role should not start with ‘ROLE_’ since it is automatically inserted. Got ‘ROLE_ADMIN’
百度了一番发现并没人遇到此问题,但我可是照着《Spring实战》一笔一划敲上去的,于是换了必应搜索,才看到国外某论坛有人提出了解决方案,其实报错信息已经描述地明明白白了 T_T
role不应该以’ ROLE_ '开头,因为它会自动插入。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin", "/user")
.hasRole("ROLE_USER") //将此处ROLE_USER改成USER即可
.antMatchers("/", "/**")
.permitAll();
}
}
改后如下列代码所示:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin", "/user")
.hasRole("USER")
.antMatchers("/", "/**")
.permitAll();
}
}
本文来自博客园,作者:Coder-Jiang,转载请注明原文链接:https://www.cnblogs.com/coderjiang/p/18118102

浙公网安备 33010602011771号