springboot 前端报has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘

My front-end project is nuxt3

The console prints and reports a crossing problem, so we can only change the back-end springboot

Solution: Add configuration class CorsConfig

package com.xxx.config;


@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedHeaders(CorsConfiguration.ALL)
                .allowedMethods(CorsConfiguration.ALL)
                .allowCredentials(true)
                .maxAge(3600);
    }
}

Guess you like

Origin blog.csdn.net/deng_zhihao692817/article/details/130850533