【springboot】全局跨域配置

@Configuration
public class WebConfig implements WebMvcConfigurer {
 	/**
     * @Description: 跨域设置
     * @Param: [corsRegistry]
     * @Return: void
     */
    @Override
    public void addCorsMappings(CorsRegistry corsRegistry) {
        corsRegistry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

你可能感兴趣的:(后端,java,spring,boot)