springboot2.1.3 配置前后端跨域问题

很简单,创建一个配置类即可,如下:

package com.app.gateway.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
					.allowedOrigins("*")
					.allowedHeaders("*")
					.allowedMethods("*")
					.maxAge(30 * 1000);
	}
	
}
原文地址:https://www.cnblogs.com/jimmyshan-study/p/11846239.html