srpingboot 跨域问题
package com.jing.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 CorsMappingConfig implements WebMvcConfigurer {
// static final String ORIGINS[] = new String[] { "GET", "POST", "PUT", "DELETE" };
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").
allowedOriginPatterns("*").
allowCredentials(true).
allowedMethods( "GET", "POST", "PUT", "DELETE").
maxAge(3600).
allowedHeaders("*");
}
}
2.4.0之后将 allowedOrigin 修改为 allowedOriginPatterns 。
引用:https://blog.csdn.net/jxysgzs/article/details/110818712