'configure'和'configureGlobal'方法之间有什么区别?

Nat*_*tch 5 java spring spring-security

我正在研究Spring Security配置,发现配置内存身份验证的最常见方法是使用configureGlobal()method:

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
    auth
      .inMemoryAuthentication()
        .withUser("user").password("userPwd").roles("USER");
  }
}
Run Code Online (Sandbox Code Playgroud)

但还有另一种方式,这是不太广泛使用,覆盖configure()从方法WebSecurityConfigurerAdapter

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
      .inMemoryAuthentication(
        .withUser("user").password("userPwd").roles("USER");
  }
}
Run Code Online (Sandbox Code Playgroud)

我只是想知道,它们之间有什么区别,使用configureGlobal()方法的重点是configure()什么?

Ali*_*ani 2

正如Spring Security 文档所说:

方法的名称configureGlobal并不重要。但是,重要的是仅在用、或AuthenticationManagerBuilder注释的类中进行配置。否则会产生不可预测的结果。@EnableWebSecurity@EnableGlobalMethodSecurity@EnableGlobalAuthentication