0
点赞
收藏
分享

微信扫一扫

Spring Security:跨域配置


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("/**");

}
};
}


}


举报

相关推荐

0 条评论