Spring Security 7 What Changed and How to Migrate Safely
Spring Security 7 migration notes: removal of and() chaining, deprecated API removal, request matcher changes and an upgrade path from 6.5.

Spring Security 7 ships with Spring Framework 7 and Spring Boot 4, and its main effect on your code is removal: APIs that were deprecated through the 6.x line are gone. If your configuration compiles without deprecation warnings on the last 6.5 release, the move is small. If it does not, the compiler will list what to fix, and the order in which you fix it matters. This post gives the upgrade path, the changes most applications hit, and the tests that tell you whether authorisation rules still behave the same. Treat the official migration guide as the authority for the complete list; what follows is the part that matters in practice, on JDK 21 or 25.
Know the baseline
Spring Security 7 builds on Spring Framework 7, which requires Jakarta EE 11 baselines for the servlet and persistence APIs, and Spring Boot 4 manages the versions for you. If you use Boot, you do not choose the Security version; you upgrade Boot and take what it brings. The minimum JDK is 17, and JDK 21 or 25 is recommended. That puts Security 7 in a combined upgrade: framework, Boot, Hibernate, Jackson and Security move together, and a failure in one can look like a failure in another. The general upgrade route for the whole stack is in the Boot guide; here the focus is Security alone.
Applications using the Jakarta EE 11 APIs on an application server should check the server's support for Servlet 6.1 before upgrading, see what is new in Jakarta EE 11.
Step 1: reach the last 6.x release
Do not jump from an old 6.x directly to 7. Upgrade to the newest 6.5 release first (and the Boot 3.5 line that matches it), and fix every deprecation warning there. In 6.5, deprecated APIs still work and the compiler tells you about them; in 7 they are missing, and the error is a compile failure far from the cause. Turn on -Xlint:deprecation and -Werror for the Security packages temporarily:
./mvnw clean test-compile -Dmaven.compiler.showDeprecation=true 2>&1 | grep -i "security" | sort -uThe list is your work queue. Commit the fixes on 6.5, deploy that, and only then take the 7 upgrade. If something breaks later, you know it came from 7 and not from a cleanup you did at the same time.
Step 2: the DSL
The chained style with and() was deprecated in 6.1 and is removed. The lambda DSL replaces it, and you have probably used it already:
@Bean
SecurityFilterChain api(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(a -> a
.requestMatchers("/public/**").permitAll()
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated())
.csrf(csrf -> csrf.ignoringRequestMatchers("/webhooks/**"))
.sessionManagement(s -> s.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.oauth2ResourceServer(o -> o.jwt(Customizer.withDefaults()));
return http.build();
}Each feature takes a Customizer, and nothing needs .and() to return to the parent. If a configuration still has http.csrf().disable().and()..., convert each call. The lambda form is explained in the lambda DSL. Applications that still extend WebSecurityConfigurerAdapter should have moved in 5.7 and 6.0; that class is long gone, and the migration is in replacing WebSecurityConfigurerAdapter.
Other removals in the same family: authorizeRequests() (use authorizeHttpRequests()), antMatchers, mvcMatchers and regexMatchers on the request-matcher registry (use requestMatchers), and AccessDecisionManager-based configuration, replaced by AuthorizationManager. Custom voters need rewriting as authorization managers.
Step 3: request matching
Matching a request path to a rule is where behaviour can change without a compile error. Spring Security 7 moves its default toward PathPatternRequestMatcher, which uses the same pattern syntax and parser as Spring MVC, and away from the AntPathRequestMatcher and MVC matcher choice you were making before. The difference is in edge cases: trailing slashes, double slashes, encoded characters, and the meaning of ** in the middle of a pattern. A rule that matched /admin/ and /admin in the old matcher may match only one now.
Two consequences follow. A rule that denies access could stop matching a variant of the URL, which leaves it falling through to the next rule, usually anyRequest().authenticated(), so the endpoint becomes less restricted than before. And a rule that allows could stop matching, which fails closed and breaks a page. Both are testable. Where you need explicit control, build the matcher yourself:
PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, "/orders/{id}")Remove servlet-path ambiguity by naming the servlet's base when your application has more than one dispatcher servlet. For a typical single-servlet Boot application, requestMatchers("/path/**") keeps working.
Step 4: dependencies
Move the Boot parent or BOM to 4.x and let it manage spring-security-*. Do not pin Security versions by hand. Check third-party modules that integrate with Security, such as Spring Session, Spring Authorization Server (now part of Spring Security itself in the 7 line, so remove the separate dependency if you used it), Keycloak adapters and SAML or OAuth client libraries. Each has its own compatibility table. Look for imports of javax.servlet that survive in old utility classes; they were already wrong on 6 and now break the build.
Step 5: test
The most valuable test in this upgrade is one that exercises every access rule. Write it before you upgrade, on 6.5, and keep it unchanged:
@WebMvcTest
@Import(SecurityConfig.class)
class AccessRulesTest {
@Autowired MockMvc mvc;
@Test void anonymous_cannot_read_admin() throws Exception {
mvc.perform(get("/admin/users")).andExpect(status().isUnauthorized());
}
@Test @WithMockUser(roles = "USER") void user_cannot_read_admin() throws Exception {
mvc.perform(get("/admin/users")).andExpect(status().isForbidden());
}
@Test @WithMockUser(roles = "ADMIN") void admin_can_read_admin() throws Exception {
mvc.perform(get("/admin/users")).andExpect(status().isOk());
}
}Add the awkward URLs: /admin/, /admin//users, /ADMIN/users, /public/../admin/users, with and without a trailing slash and an encoded dot. These are the cases where matcher behaviour differs, and the old and new versions should give identical answers for each. If a result changes, decide deliberately which answer is correct. Run the same test class on both versions.
Step 6: read the release notes
The Spring Boot 4.0 release notes and the Security migration guide list renamed properties, changed defaults and removed classes. Scan them for features you use: CSRF handling for single-page apps, the default password encoder, SecurityContextHolder strategy for virtual threads, and OAuth2 client defaults. Pay attention to anything described as a changed default, since a default change does not fail the build.
Rollback
Keep the 6.5 branch deployable until 7 has run in production for a release cycle. Because the access test is version-neutral, you can run it on both and compare. A staged rollout (a canary instance, then the fleet) is better than a single switch for authentication changes, since a mistake there locks users out.
When this does not apply
Applications still on Spring Framework 6 and Boot 3 do not need any of this yet; they need the cleanup of deprecations, which pays off whenever the upgrade comes. The official sources are the Spring Security migration guide and the Spring Boot 4.0 release notes.


