title: Problem with configure(HttpSecurity http) error: Can't configure antMatchers after anyRequest
body: <p>I'm trying do one example <a href="https://www.boraji.com/spring-mvc-5-spring-security-5-hibernate-5-example" rel="nofollow noreferrer">here link</a> and i eliminated all possible errors, but stayed one:</p>
  
  <p>Error:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: Can't configure antMatchers after anyRequest
  </code></pre>
  
  <p>In the end of stacktrace:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: Can't configure antMatchers after anyRequest
      at org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry.antMatchers(AbstractRequestMatcherRegistry.java:122)
      at com.windigital.config.WebSecurityConfig.configure(WebSecurityConfig.java:37)
  </code></pre>
  
  <p>WebSecurityConfig:</p>
  
  <pre><code>@EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      private final UserDetailsService userDetailsService;
  
      @Autowired
      public WebSecurityConfig(UserDetailsService userDetailsService) {
          this.userDetailsService = userDetailsService;
      }
  
      @Bean
      public BCryptPasswordEncoder passwordEncoder() {
          return new BCryptPasswordEncoder();
      }
  
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests().anyRequest().hasAnyRole("ADMIN", "USER")
                  .and()
                  .authorizeRequests().antMatchers("/login**").permitAll()
                  .and()
                  .formLogin().loginPage("/login").loginProcessingUrl("/loginAction").permitAll()
                  .and()
                  .logout().logoutSuccessUrl("/login").permitAll()
                  .and()
                  .csrf().disable();
      }
  }
  </code></pre>
  
  <p>The problem in this antMatcher:</p>
  
  <pre><code>.antMatchers("/login**")
  </code></pre>
  
  <p>Please help me, and tell me about this configure() method or give me links. Thank you!</p>