java跨域配置

x33g5p2x  于2022-05-28 转载在 Java  
字(0.6k)|赞(0)|评价(0)|浏览(370)

java跨域:

  1. import org.springframework.context.annotation.Configuration;
  2. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  3. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  4. @Configuration
  5. public class MyWebConfig implements WebMvcConfigurer {
  6. @Override
  7. public void addCorsMappings(CorsRegistry registry) {
  8. registry.addMapping("/**")
  9. .allowedOrigins("*")
  10. .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
  11. //.allowCredentials(true)
  12. .allowedHeaders("*")
  13. .maxAge(3600);
  14. }
  15. }

相关文章

最新文章

更多