1 import org.springframework.context.annotation.Configuration;
 2 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 3 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 4 
 5 /**
 6  * @Author:CoderZZ
 7  * @Description:Spring Boot全局支持CORS(跨源请求)
 8  * @Date:Created in 10:57 2018/2/8.
 9  */
10 @Configuration
11 public class WebCorsConfigurerAdapter extends WebMvcConfigurerAdapter
12 {
13 
14     @Override
15     public void addCorsMappings(CorsRegistry registry) {
16         registry.addMapping("/**").
17                 allowedOrigins("*").
18                 allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS").
19                 allowedHeaders("Content-Type","Access-Control-Allow-Headers","Authorization","X-Requested-With").
20                 allowCredentials(true);
21     }
22 }

 

相关文章:

  • 2022-12-23
  • 2022-01-19
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-10-15
  • 2021-09-21
猜你喜欢
  • 2021-05-25
  • 2021-05-21
  • 2021-12-04
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
相关资源
相似解决方案