zoukankan      html  css  js  c++  java
  • java跨域解决

    import java.util.ArrayList;
    import java.util.List;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.cors.CorsConfiguration;
    import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
    import org.springframework.web.filter.CorsFilter;
    import org.springframework.web.servlet.config.annotation.CorsRegistration;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    @Configuration
    public class CorsConfig
      extends WebMvcConfigurerAdapter
    {
      public void addCorsMappings(CorsRegistry registry)
      {
        registry.addMapping("/**").allowedOrigins(new String[] { "*" }).allowCredentials(true).allowedMethods(new String[] { "GET", "HEAD", "POST", "DELETE", "PUT", "OPTIONS" }).maxAge(3600L);
      }
      
      private CorsConfiguration buildConfig()
      {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        List<String> list = new ArrayList();
        list.add("*");
        corsConfiguration.setAllowedOrigins(list);
        
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        return corsConfiguration;
      }
      
      @Bean
      public CorsFilter corsFilter()
      {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", buildConfig());
        return new CorsFilter(source);
      }
    }
  • 相关阅读:
    《C#微信开发系列(2)-自定义菜单管理》
    《C#微信开发系列(1)-启用开发者模式》
    python多进程: multiprocessing Pool 和tqdm
    前端
    python 缓存
    python pymysql
    python paramiko模块
    Linux之TCPIP内核参数优化
    python进程、线程、协程、IO多路复用
    python socket
  • 原文地址:https://www.cnblogs.com/shihaiming/p/9474606.html
Copyright © 2011-2022 走看看