package com.highdatas.mdm.util; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.concurrent.Executor; /** * @author kimi * @description * @date 2019-12-12 16:45 */ @Configuration public class OriginConfig implements WebMvcConfigurer, AsyncConfigurer { @Autowired CommonInterceptor commonInterceptor; @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedHeaders("Content-Type","X-Requested-With","accept,Origin","Access-Control-Request-Method","Access-Control-Request-Headers","token") .allowedMethods("*") .allowedOrigins("*") .allowCredentials(true); } @Override public void addInterceptors(InterceptorRegistry registry) { InterceptorRegistration interceptorRegistration = registry.addInterceptor(commonInterceptor); interceptorRegistration.excludePathPatterns("/designer/**","/upload/**", "/process/**", "/processes/**", "/swagger-ui.html", "/webjars/**", "/swagger-resources/**", "/v2/api-docs", "/"); } @Override @Bean public Executor getAsyncExecutor() { ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor(); //è®¾ç½®æ ¸å¿ƒçº¿ç¨‹æ•° threadPool.setCorePoolSize(10); //设置最大线程数 threadPool.setMaxPoolSize(100); //çº¿ç¨‹æ± æ‰€ä½¿ç”¨çš„ç¼“å†²é˜Ÿåˆ— threadPool.setQueueCapacity(10); //ç‰å¾…任务在关机时完æˆ--表明ç‰å¾…所有线程执行完 threadPool.setWaitForTasksToCompleteOnShutdown(true); // ç‰å¾…æ—¶é—´ (默认为0ï¼Œæ¤æ—¶ç«‹å³åœæ¢ï¼‰ï¼Œå¹¶æ²¡ç‰å¾…xxç§’åŽå¼ºåˆ¶åœæ¢ threadPool.setAwaitTerminationSeconds(60); // 线程åç§°å‰ç¼€ threadPool.setThreadNamePrefix("MDM-Async-"); // åˆå§‹åŒ–线程 threadPool.initialize(); return threadPool; } @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return null; } }