springSecurity5 使用:
http.formLogin().loginPage("/login");
报错如下图:
springsucurity5 中 需要给 自己定义的请求加权限:
失败代码如下:
public class MySecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { //定制请求的授权规则 http.authorizeRequests().antMatchers("/").permitAll() .antMatchers("/manage/**").hasRole("manage") .antMatchers("/view/**").hasRole("view") .antMatchers("/db/**").hasRole("db").anyRequest().authenticated(); http.formLogin().loginPage("/login");
修正后代码如下:
public class MySecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/").permitAll() .antMatchers("/login").permitAll() .antMatchers("/manage/**").hasRole("manage") .antMatchers("/view/**").hasRole("view") .antMatchers("/db/**").hasRole("db").anyRequest().authenticated(); //http.formLogin(); http.formLogin().loginPage("/login");