Commit 229dde85 authored by 张永's avatar 张永

跨域

parent 38716cdc
...@@ -2,6 +2,7 @@ package com.egolm.shop.common.config; ...@@ -2,6 +2,7 @@ package com.egolm.shop.common.config;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
...@@ -18,6 +19,27 @@ public class WebMvcConfig implements WebMvcConfigurer { ...@@ -18,6 +19,27 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Autowired @Autowired
LogInterceptor logInterceptor; LogInterceptor logInterceptor;
/**
*
* @Title: addCorsMappings
* @Description: TODO(解决跨域 https://www.toutiao.com/i6720374197358428685/)
* @param @param registry 设定文件
* @return 返回类型
* @throws
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 拦截所有的url
.allowedOrigins("*") // 放行哪些原始域,比如"http://domain1.com,https://domain2.com"
.allowCredentials(true) // 是否发送Cookie信息
.allowedMethods("GET", "POST", "PUT", "DELETE") // 放行哪些原始域(请求方式)
.allowedHeaders("*"); // 放行哪些原始域(头部信息)
WebMvcConfigurer.super.addCorsMappings(registry);
}
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
InterceptorRegistration logsRegistration = registry.addInterceptor(logInterceptor).addPathPatterns("/**"); InterceptorRegistration logsRegistration = registry.addInterceptor(logInterceptor).addPathPatterns("/**");
......
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