欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

跨域解决方案  

程序员文章站 2024-03-15 13:14:29
...
<dependency>
	<groupId>com.thetransactioncompany</groupId>
	<artifactId>cors-filter</artifactId>
	<version>2.6</version>
</dependency>


@Configuration
public class CorsConfig {
 
	@Bean
	public FilterRegistrationBean corsFilter() {
		Properties props = new Properties();
		props.setProperty("cors.allowGenericHttpRequests", "true");
		props.setProperty("cors.allowOrigin", "*");
		props.setProperty("cors.allowSubdomains", "true");
		props.setProperty("cors.supportedMethods", "GET, HEAD, POST, OPTIONS");
		props.setProperty("cors.supportedHeaders", "*");
		props.setProperty("cors.supportsCredentials", "true");
		props.setProperty("cors.maxAge", "3600");
		CORSConfiguration config = null;
		try {
			config = new CORSConfiguration(props);
		} catch (CORSConfigurationException e) {
			e.printStackTrace();
		}
		FilterRegistrationBean bean = new FilterRegistrationBean(new CORSFilter(config));
		bean.setOrder(0);
		return bean;
	}
}

上一篇: redis 安装  

下一篇: 安装 etcd etcd