springboot 跨域设置

    /**
	 * Configuration cors
	 */
	@Configuration
	public class MyConfiguration {
    	@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;
		}
	}

posted @ 2020-01-13 09:43  老年游侠  阅读(153)  评论(0编辑  收藏  举报