Spring security application of antMatcher vs. antMatchers
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In older Spring Security configuration, antMatcher and antMatchers looked almost identical but served different roles. One selected which requests a whole security configuration applied to, while the other declared authorization rules inside that configuration. Confusing them often produced code that looked reasonable but did not protect the intended routes.
What antMatcher Did
In the WebSecurityConfigurerAdapter style, http.antMatcher("/api/**") scoped the entire HttpSecurity configuration to matching requests.
That means this configuration chain only applies to paths under /api/. Requests outside that scope are handled elsewhere.
What antMatchers Did
Inside authorizeRequests(), antMatchers(...) defined authorization rules for specific request patterns within the active security chain.
So the division of responsibility was:
- '
antMatcherdecided whether the chain applied at all' - '
antMatchersexpressed access rules inside that chain'
Why the Difference Mattered
Suppose you scoped the chain with http.antMatcher("/api/**") and then wrote an authorization rule for /admin/**. That rule would never run for /admin/** requests because those requests would never enter the /api/** chain in the first place.
That is why the names caused confusion. They sounded interchangeable, but they operated at different structural levels.
Multiple Security Chains Made This Even More Important
The distinction became more obvious when applications used more than one security configuration.
Here, order and chain scope both matter. A broader chain can catch requests before a later, more specific chain gets a chance.
The Modern API Replaced These Names
Current Spring Security no longer encourages WebSecurityConfigurerAdapter, antMatcher, or antMatchers. The modern style uses SecurityFilterChain, securityMatcher, and requestMatchers.
The conceptual split is the same as before: one matcher selects the chain, and another defines rules within it.
Test Matcher Scope Explicitly
Because matcher scope and rule scope are different concerns, integration tests are often the quickest way to confirm that the expected chain is handling the expected requests. A rule that looks correct on paper may still be unreachable if the surrounding chain selector is too narrow or ordered incorrectly.
When debugging legacy configurations, ask two separate questions: did the request enter this chain at all, and if it did, which authorization rule matched inside it. That mental split mirrors the API design and prevents many false assumptions.
Common Pitfalls
A common mistake was treating antMatcher as if it were just a shorter spelling of antMatchers. It was not.
Another was writing rules inside a chain for routes that the chain could never see. Those rules looked valid in code review but had no effect at runtime.
Teams also carried old examples into newer Spring Security versions without updating the API shape. In current code, securityMatcher and requestMatchers are the clearer equivalents.
Summary
- In legacy Spring Security,
antMatcherscoped the whole security chain. - '
antMatchersdefined authorization rules inside that selected chain.' - Similar names caused many misconfigurations where rules never matched real requests.
- In modern Spring Security, use
securityMatcherfor chain scope andrequestMatchersfor route rules. - When multiple chains exist, verify both matcher scope and chain order.
Related reading
- Spring Security blocks POST requests despite SecurityConfig
- Spring Security Caused by org.springframework.security.config.annotation.AlreadyBuiltException This object has already been built
- Spring Security Configuration - HttpSecurity vs WebSecurity
- Spring security CORS Filter
- Spring Security deprecated issue
- Spring Security exposing AuthenticationManager without WebSecurityConfigurerAdapter
- Spring Security HTTP Basic for RESTFul and FormLogin Cookies for web - Annotations
- Spring Security in Spring Boot 3

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.