原springboot版本2.2.5.release,后升级到2.7.12
原版本没配置cors访问正常,升级之后报错
get请求可以,post请求就是这个错误
2.7.12添加如下代码:添加之后报错如图
@SpringBootApplication
public class Application implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
CorsRegistration corsRegistration = registry.addMapping("/**");
corsRegistration = corsRegistration.allowCredentials(true);
corsRegistration = corsRegistration.allowedOriginPatterns(CorsConfiguration.ALL);
corsRegistration = corsRegistration.allowedHeaders(CorsConfiguration.ALL);
corsRegistration = corsRegistration.allowedMethods(CorsConfiguration.ALL);
corsRegistration.maxAge(3600);
}
}