package com.sgcc.epri.platform;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@SpringBootApplication
@EnableScheduling
@EnableTransactionManagement
@EnableDiscoveryClient
@MapperScan("com.sgcc.epri.platform.mapper")
public class SmpApplication {
public static void main(String[] args) {
SpringApplication.run(SmpApplication.class, args);
}
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true); // 允許cookies跨域
config.addAllowedOrigin("*");// 允許向該服務器提交請求的URI,*表示全部允許。。這裏儘量限制來源域,比如http://xxxx:8080 ,以降低安全風險。。
config.addAllowedHeader("*");// 允許訪問的頭信息,*表示全部
config.setMaxAge(18000L);// 預檢請求的緩存時間(秒),即在這個時間段裏,對於相同的跨域請求不會再預檢了
config.addAllowedMethod("*");// 允許提交請求的方法,*表示全部允許,也可以單獨設置GET、PUT等
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}