import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.garfield.brush.interceptor.UserContextInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.util.List;
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
protected void addCorsMappings(CorsRegistry registry) {
//允许访问的地址
registry.addMapping("/**").
//请求来源
allowedOrigins("*").
//请求方式
allowedMethods("*").
//请求头
allowedHeaders("*").
//支持cookie
allowCredentials(true).
//对外暴露的header
exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L);
}
}
前端如果报这个错,把这行加上:
.exposedHeaders("Access-Control-Allow-Origin")