1.在WebSecurityConfigurerAdapter的子类的方法
protected void configure(HttpSecurity http) throws Exception
中增加如下片段:
http.cors().and(). 。。。。。。
2.增加如下配置Bean
package com.appbyte.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration(proxyBeanMethods = false)
public class MyCorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
};
}
}
版权声明:本文为amadeus_liu2原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。