CORS in Spring Boot controls which frontend origins are allowed to make cross-origin requests to the backend, configured either per-controller with @CrossOrigin or globally through a WebMvcConfigurer bean.
A single-page app hosted at https://app.example.com calls the Spring Boot API at a different origin; without CORS configuration the browser blocks the response, so the backend explicitly allows that origin through a global CORS configuration.
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("https://app.example.com")
.allowedMethods("GET", "POST", "PUT", "DELETE");
}
}A concise interview answer is
I configure CORS globally with a WebMvcConfigurer overriding addCorsMappings, restricting allowedOrigins to the specific frontend domain rather than using a wildcard, especially if credentials are involved. For a one-off endpoint, @CrossOrigin on the controller works too, but I prefer the global, centralized approach for consistency.
Last updated: 16 July 2026
Previous question: Your application needs data from an external REST API. How would you use RestTemplate or WebClient to consume it in Spring Boot?