注册
登录
Spring或Springboot中解决跨域问题
package com.et.conf;
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 WebAppConfigurer implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
.allowCredentials(true)
.allowedOrigins("*")
.maxAge(3600);
}
}