I am using spring boot 1.2.8 but class import org.springframework.web.bind.annotation.CrossOrigin
is not present. What is the best way to do that without this class?
Asked
Active
Viewed 353 times
2

Fernando V
- 263
- 4
- 14
-
Possible duplicate of [Spring Boot Security CORS](http://stackoverflow.com/questions/40286549/spring-boot-security-cors) – pvpkiran May 12 '17 at 18:43
-
Btw: why 1.2.x ? – Marged May 14 '17 at 09:20
-
I suggest you update to 1.5.x – Tanmay Delhikar May 14 '17 at 09:22
1 Answers
2
Add below bean configuration in your application main class:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class MyConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**").allowedOrigins("*").maxAge(3600);
}
};
}
}

Tanmay Delhikar
- 1,275
- 11
- 16