Spring Boot 允许跨域

lemon发布

 @Bean
    public CorsConfigurationSource corsConfigurationSource(){
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedOrigin("*");
        configuration.setAllowedMethods(Arrays.asList("GET", "POST", "DELETE", "PUT","OPTIONS","HEAD"));
        configuration.addAllowedHeader("*");
        configuration.setAllowCredentials(Boolean.TRUE);
        configuration.applyPermitDefaultValues();
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }

    @Bean
    CorsFilter corsFilter(CorsConfigurationSource corsConfigurationSource) {
        CorsFilter corsFilter = new CorsFilter(corsConfigurationSource);
        return corsFilter;
    }
分类: Java

4 条评论

http://forum1.shellmo.org · 2020年6月20日 下午1:31

Everything is very open with a very clear explanation of the challenges.
It was really informative. Your site is very helpful.
Thank you for sharing! http://forum1.shellmo.org

www.kitsunemusicacademy.com · 2020年6月21日 下午9:33

Very nice article, just what I was looking for. http://www.kitsunemusicacademy.com

http://bbs.ispt.com.cn/home.php?mod=space&uid=78225 · 2020年6月22日 下午4:13

I’m extremely impressed with your writing skills as well as with the
layout on your blog. Is this a paid theme or did you modify it yourself?
Either way keep up the excellent quality writing, it is rare to see a nice blog like this one
nowadays. http://bbs.ispt.com.cn/home.php?mod=space&uid=78225

watch · 2021年2月6日 下午8:21

Excellent post, I am planning to spend much more time researching this subject matter. Helen-Elizabeth Field Trisha

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注