package com.get;
importorg.spring framework.boot.spring应用程序;
importorg.spring framework.boot.auto configure.springbootapplication;
importorg.spring framework.boot.web.servlet.multipartconfigfactory;
importorg.spring framework.cloud.net flix.eureka.enableeurekaclient;
importorg.spring framework.cloud.net flix.zuul.enablezulproxy;
importorg.spring帧work.context.annotation.bean;
importorg.spring framework.context.annotation.configuration;
importorg.spring framework.web.bind.annotation.cross origin;
importorg.spring framework.web.CORS.CORS configuration;
importorg.spring framework.web.CORS.urlbasedcorsconfigurationsource;
importorg.spring framework.web.filter.CORS filter;
import javax.servlet.multipartconfigelement;
@Configuration
@EnableZuulProxy
@EnableEurekaClient
@ springbootapplicationpublicclasseurekazulclientapplication { publicstaticvoidmain { string [ ] args } }
spring application.run (eurekazuulclientapplication.class,args );
}
@ beanpubliccorsfiltercorsfilter () {
finalurlbasedcorsconfigurationsourcesource=newurlbasedcorsconfigurationsource (;
finalcorsconfigurationconfig=newcorsconfiguration (;
config.setallowcredentials (true; 允许cookies穿越域
config.addallowedorigin('* '; //表示允许向该服务器提交请求的所有URI、*都是允许的。 在此,为了降低安全风险,尽量限制http://xxxx:8080等源域。
config.addallowedheader('* '; //允许访问的头信息,*表示全部
config.setmaxage(18000L; //预检请求的高速缓存时间(秒),也就是说,在此时间段内,不会对同一域间请求执行预检
config.addallowedmethod('* '; //允许提交请求的方法,*表示全部允许,也可以分别设定GET、PUT等
config.addallowedmethod('head );
config.addallowedmethod('get ); 允许//GET的请求方法
config.addallowedmethod('put );
config.addallowedmethod('post );
config.addallowedmethod (' delete );
config.addallowedmethod('patch );
source.registercorsconfiguration (,config ); returnnewcorsfilter(source;
(/**
*文件上传配置
*
* @ return */@ beanpublicmultipartconfigelementmultipartconfigelement (
multipartconfigfactoryfactory=newmultipartconfigfactory (; //单个数据大小
factory.setmaxfilesize(10240kb ); //KB,MB
//总上传数据大小
factory.setmaxrequestsize (102400 kb ); return factory.createmultipartconfig (;
}
}