1st Example For All Location
1 2 3 4 5 6 7 8 9 |
@Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**"); } } |
2nd Example For Validate which location and which method to allow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
@Configuration @EnableWebMvc public class AppConfig extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("http://localhost:8585", "http://localhost:8787") .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") .allowedHeaders("X-Auth-Token", "Content-Type") .exposedHeaders("custom-header1", "custom-header2") .allowCredentials(false) .maxAge(4800); } } |