springBoot 2.1.2.RELEASE升级到springBoot 2.5.10报
When allowCredentials is true, allowedOrigins cannot contain the special value “*“
增加一个配置类就可以解决问题
package com.example.springboot.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
static final String ORIGINS[] = new String[]{"GET", "POST", "PUT", "DELETE"};
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").
allowedOriginPatterns("*").
allowCredentials(true).
allowedMethods(ORIGINS).
maxAge(3600);
}
}
参考:https://blog.csdn.net/qq_41822960/article/details/119873880