|
@@ -1,7 +1,12 @@
|
|
package org.fouram;
|
|
package org.fouram;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
|
+import org.springframework.web.cors.CorsConfiguration;
|
|
|
|
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
+import org.springframework.web.filter.CorsFilter;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
@@ -29,14 +34,25 @@ public class WebConfigurer extends WebMvcConfigurationSupport {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 添加跨域请求支持
|
|
* 添加跨域请求支持
|
|
- *
|
|
|
|
- * @param registry
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param
|
|
*/
|
|
*/
|
|
- @Override
|
|
|
|
- public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ @Order(100)
|
|
|
|
+ public CorsFilter corsFilter() {
|
|
|
|
+ CorsConfiguration config = new CorsConfiguration();
|
|
log.warn("开启跨域支持");
|
|
log.warn("开启跨域支持");
|
|
- registry.addMapping("/**").allowedOrigins("*").allowedHeaders("*")
|
|
|
|
- .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE").maxAge(3600).allowCredentials(true);
|
|
|
|
- super.addCorsMappings(registry);
|
|
|
|
|
|
+ config.addAllowedOrigin("*");
|
|
|
|
+ config.addAllowedMethod("*");
|
|
|
|
+ config.addAllowedHeader("*");
|
|
|
|
+ config.setAllowCredentials(true);
|
|
|
|
+
|
|
|
|
+ config.setMaxAge(3600L);
|
|
|
|
+
|
|
|
|
+ UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
|
|
|
|
+ configSource.registerCorsConfiguration("/**", config);
|
|
|
|
+
|
|
|
|
+ return new CorsFilter(configSource);
|
|
}
|
|
}
|
|
}
|
|
}
|