package com.example.lm.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 解决前后端分离开发时的跨域问题
*/
@Configuration
public class CrossConfig implements WebMvcConfigurer {
/**
* spring boot解决跨域访问问题
* @param registry
*/
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.maxAge(3600)
.allowedHeaders("*");
}
}
推荐使用WebMvcConfigurer接口来完成配置。。。