Commit e26af6ad authored by luyuan's avatar luyuan

update

parent 8650d0f9
......@@ -30,7 +30,7 @@ import java.util.*;
* Created by wuxw on 2017/2/23.
*/
@CrossOrigin
@CrossOrigin(origins = "*", allowedHeaders = "*", maxAge = 86400)
public class BaseController extends AppBase {
......@@ -195,6 +195,7 @@ public class BaseController extends AppBase {
headers.put("user_id", headers.get("user-id"));
}
headers.put("Access-Control-Allow-Origin", "*");
}
/**
......
......@@ -53,6 +53,6 @@ public class CustomMVCConfiguration extends WebMvcConfigurerAdapter {
private static final String ORIGINS[] = new String[] { "GET", "POST", "PUT", "DELETE" };
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*").allowCredentials(true).allowedMethods(ORIGINS).maxAge(3600);
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*");
}
}
......@@ -4,6 +4,10 @@ import com.java110.boot.filter.JwtFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* Created by wuxw on 2018/5/2.
......@@ -121,4 +125,27 @@ public class ServiceConfiguration {
return registrationBean;
}
@Bean
public FilterRegistrationBean corsFilter() {
// 创建 CorsConfiguration 对象后添加配置
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
// 设置放行哪些原始域
corsConfiguration.addAllowedOrigin("*");
// 放行哪些原始请求头部信息
corsConfiguration.addAllowedHeader("*");
// 放行哪些请求方法
corsConfiguration.addAllowedMethod("*");
// 添加映射路径
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfiguration);
CorsFilter corsFilter = new CorsFilter(source);
FilterRegistrationBean<CorsFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(corsFilter);
registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return registrationBean;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment