跨域:cors
加一个配置类:
package com.yangoxix.lovegoing.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* @program: lovegoing
* @description: my
* @author: chenzou
* @create: 2021-10-12 10:09
**/
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").
allowedOrigins("http://chenjunbin.ren:3000").
allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS").
allowedHeaders("Content-Type","Access-Control-Allow-Headers","Authorization","X-Requested-With").
allowCredentials(true);
}
}