(Domänenübergreifender Konfigurationsfehler) java.lang.IllegalArgumentException: Wenn „allowCredentials“ wahr ist, kann „allowedOrigins“ dies nicht tun

Berichterstattung über domänenübergreifende Konfigurationsfehler

Lösung: Ersetzen Sie .allowedOrigins durch .allowedOriginPatterns

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @author : 其然乐衣Letitbe
 * @date : 2022/12/2
 */

// 请求跨域
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
//                .allowedOrigins("*")   // 如果用这行报错,那么换用的下面那行即可
                .allowedOriginPatterns("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

Guess you like

Origin blog.csdn.net/QRLYLETITBE/article/details/128153372