怎么解决springboot 403 问题

2023-06-26,

本篇内容介绍了“怎么解决springboot 403 问题”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

添加WebAppConfigurer 配置

@Configuration
@EnableAutoConfiguration
public class WebAppConfigurer extends WebMvcConfigurerAdapter {
    public WebAppConfigurer() {
    }

    @Bean
    public FilterRegistrationBean corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.addAllowedMethod("*");
        source.registerCorsConfiguration("/**", config);
        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
        bean.setOrder(0);
        return bean;
    }
}

“怎么解决springboot 403 问题”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注本站网站,小编将为大家输出更多高质量的实用文章!

《怎么解决springboot 403 问题.doc》

下载本文的Word格式文档,以方便收藏与打印。