Your Spring Boot backend needs to accept cross-origin requests from a specific frontend domain. Explain how you would configure CORS policies in your application.

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.

Key Points

Example

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");
    }
}

Interview Tip

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?

Next question: You need a simple Spring Boot web app with a static homepage and a page showing the current server time. What project structure would you use?

More Spring Boot - Level III (Scenario Based) interview questions

All Spring Boot - Level III (Scenario Based) questions