使用 springSecurity 我的配置好像没有生效

原理都懂,实践一把发现代码没有生效,有过经验的麻烦指导一下,谢谢。

问题为,配置了 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");

    }
}
阅读 6.1k
1 个回答

重点是要加 @Autowired ,不知道什么原因

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("user")
                .password("12345")
                .roles("USER");
    }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进