2

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?

Fernando V
  • 263
  • 4
  • 14

1 Answers1

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