Home » Tip Bank » Web Development
  • Email Article
  • Comment on this Article
  • Share Article
    • Digg
    • del.icio.us
    • Newvine
    • furl
    • StumbleUpon
    • BlinkList
    • Newsvine
    • Magnolia
    • Facebook
    • Tailrank
    • Slashdot
    • Technorati
    • Google Bookmarks
    • Yahoo Favorites
    • Windows Live
    • Ask
Language: Web
Expertise: Intermediate
Jun 21, 2017

CORS Support in Spring

Spring MVC has implicit CORS support, so to use the controller method CORS configuration with @CrossOrigin annotation in your Spring Boot application does not require any specific configuration.

The global CORS configuration can be defined by registering a WebMVCConfigurer bean with a customized addCorsMappings(CorsRegistry) method, as you can see in the code below:

@Configuration
public class MyConfiguration {

     @Bean
     public WebMvcConfigurer corsConfigurer() {
            return new WebMvcConfigurerAdapter()  {
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                          registry.addMapping("/api/**");
                }
            };
    }
}
Octavia Anghel
 
Submit a Tip
Browse "Web Development" Tips
Browse All Tips
enable-javascript.com
googlecode.com