|
|
@ -5,6 +5,11 @@ import org.springframework.boot.SpringApplication; |
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
|
|
|
import org.springframework.cloud.openfeign.EnableFeignClients; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin; |
|
|
|
import org.springframework.web.cors.CorsConfiguration; |
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
|
|
|
import org.springframework.web.filter.CorsFilter; |
|
|
|
|
|
|
|
@EnableDiscoveryClient |
|
|
|
@EnableFeignClients(basePackages = {"com.wh.*"}) |
|
|
@ -14,6 +19,26 @@ import org.springframework.cloud.openfeign.EnableFeignClients; |
|
|
|
"com.wh.*" |
|
|
|
}) |
|
|
|
public class WarehouseApplication { |
|
|
|
|
|
|
|
private CorsConfiguration buildConfig() { |
|
|
|
CorsConfiguration corsConfiguration = new CorsConfiguration(); |
|
|
|
corsConfiguration.addAllowedOrigin("*"); |
|
|
|
corsConfiguration.addAllowedHeader("*"); |
|
|
|
corsConfiguration.addAllowedMethod("*"); |
|
|
|
corsConfiguration.setAllowCredentials(true);//这两句不加不能跨域上传文件,
|
|
|
|
corsConfiguration.setMaxAge(3600l);//加上去就可以了
|
|
|
|
return corsConfiguration; |
|
|
|
} |
|
|
|
/** |
|
|
|
* 跨域过滤器 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Bean |
|
|
|
public CorsFilter corsFilter() { |
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|
|
|
source.registerCorsConfiguration("/**", buildConfig()); // 4
|
|
|
|
return new CorsFilter(source); |
|
|
|
} |
|
|
|
public static void main(String[] args) { |
|
|
|
SpringApplication.run(WarehouseApplication.class,args); |
|
|
|
} |
|
|
|