Spring Security is the standard way to secure a Spring MVC application, covering authentication (who you are) and authorization (what you can do), along with protections against common web attacks. It can be wired up with Java configuration or, in legacy apps, XML, and it plugs into the same filter chain that handles every incoming request.
A typical setup restricts /admin/** to users with the ADMIN role, allows /api/public/** for everyone, and requires authentication for everything else, all declared in one SecurityFilterChain bean.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth -> auth
.requestMatchers("/admin/**").hasRole("ADMIN")
.requestMatchers("/api/public/**").permitAll()
.anyRequest().authenticated())
.formLogin(Customizer.withDefaults());
return http.build();
}A concise interview answer is
I secure Spring MVC apps with Spring Security, configuring a SecurityFilterChain bean to define which URLs need authentication or specific roles, and using @PreAuthorize for method-level checks. For stateless APIs I'd add JWT-based authentication, and for user-facing login I'd consider OAuth2 for single sign-on.
Last updated: 16 July 2026
Previous question: How does Spring MVC differentiate between different types of exceptions?
Next question: How does Spring Security integrate with Spring MVC?