原理都懂,实践一把发现代码没有生效,有过经验的麻烦指导一下,谢谢。
问题为,配置了 spring security 的路径权限,配置了一个内存用户,但还是走的默认的内存用户生成,还给我动态生成了一个密码,我的代码是这样的,现在的现象是访问任何路径都需要权限
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/home").authenticated()
.anyRequest().permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("9420").password("9420").roles("user");
}
}
重点是要加 @Autowired ,不知道什么原因