SpringCloud学习笔记-服务网关-Zuul-跨越

SpringCloud学习笔记-服务网关-Zuul-跨越_第1张图片
@CrossOrigin   
官网参考:https://spring.io/blog/2015/06/08/cors-support-in-spring-framework
参考二:https://blog.csdn.net/w_linux/article/details/81142413

 

 

CorsConfig

package com.hx.apigeteway.config;


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 java.util.Arrays;

/**跨越配置
 *
 */
@Configuration
public class CorsConfig {

    @Bean
    public CorsFilter corsFilter(){
        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration config=new CorsConfiguration();

        config.setAllowCredentials(true);
        config.setAllowedOrigins(Arrays.asList("*")); //http:www.myTest.com
        config.setAllowedHeaders(Arrays.asList("*"));
        config.setAllowedMethods(Arrays.asList("*"));
        config.setMaxAge(300L);  //时间

        source.registerCorsConfiguration("/**",config); //所有路径
        return new CorsFilter(source);
    }
}

SpringCloud学习笔记-服务网关-Zuul-跨越_第2张图片

你可能感兴趣的:(SpringCloud)