|
- package com.lecoo.kjg.web;
-
- import com.jeesite.common.config.Global;
- import com.jeesite.common.io.PropertiesUtils;
- import com.lecoo.kjg.web.config.BusinessLoggerInterceptor;
- import com.lecoo.kjg.web.sys.bean.filter.BodyReaderRequestFilter;
- import com.lecoo.kjg.web.sys.service.support.DeviceServiceSupport;
- import com.lecoo.kjg.web.utils.ResponseCodeUtil;
- import org.apache.commons.lang3.concurrent.BasicThreadFactory;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.boot.web.servlet.FilterRegistrationBean;
- import org.springframework.boot.web.servlet.MultipartConfigFactory;
- import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
- import org.springframework.context.annotation.Bean;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.http.client.BufferingClientHttpRequestFactory;
- import org.springframework.http.client.SimpleClientHttpRequestFactory;
- import org.springframework.http.converter.StringHttpMessageConverter;
- import org.springframework.scheduling.TaskScheduler;
- import org.springframework.scheduling.annotation.EnableAsync;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
- import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
- import org.springframework.web.client.DefaultResponseErrorHandler;
- import org.springframework.web.client.RestTemplate;
-
- import javax.servlet.MultipartConfigElement;
- import java.nio.charset.Charset;
- import java.util.Collections;
- import java.util.Map;
- import java.util.TimeZone;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.ScheduledThreadPoolExecutor;
-
- /**
- * 1
- * 项目启动类,
- *
- * @author ***
- * @version 2018-7-10
- * <p>
- * 此项目中的jeesite.yml文件可以自行配置,相较于jeesite-core.yml优先级更高,
- * 一但配置了jeesite.yml就自动覆盖jeesite-core.yml中的配置 ---个人见解
- */
- //注意此启动类中数组的第0个元素出必须加上不能删除,否则项目报错
- @SpringBootApplication(scanBasePackages = {"com.jeesite.modules", "com.lecoo.kjg.web"})
- @EnableAsync
- @EnableScheduling
- @EnableBatchProcessing
- public class Application extends SpringBootServletInitializer implements CommandLineRunner {
- private final static Logger log = LoggerFactory.getLogger(Application.class);
-
- @Value("${spring.profiles.active}")
- private String activeProfile;
-
- @Autowired
- BusinessLoggerInterceptor actionTrackInterceptor;
-
- @Autowired
- StringRedisTemplate stringRedisTemplate;
-
- @Autowired
- DeviceServiceSupport deviceServiceSupport;
-
- public static void main(String[] args) {
- TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
- SpringApplication app = new SpringApplication(Application.class);
- app.setDefaultProperties(PropertiesUtils.getInstance().getProperties());
- app.run(args);
- }
-
- /**
- * 业务状态码和提联想ThinkFace办公系统示文字
- *
- * @return Map
- */
- @Bean
- public Map<Integer, Map<String, String>> responseMessageMap() {
- log.info("Active {} profile", activeProfile);
- return ResponseCodeUtil.getResponseCodeAndMsgMap();
- }
-
- @Bean
- public RestTemplate restTemplate() {
- SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
- requestFactory.setReadTimeout(25000);
-
- BufferingClientHttpRequestFactory bufferingClientHttpRequestFactory = new BufferingClientHttpRequestFactory(requestFactory);
- RestTemplate restTemplate = new RestTemplate(bufferingClientHttpRequestFactory);
- restTemplate.getMessageConverters().add(1, new StringHttpMessageConverter(Charset.forName("UTF-8")));
- restTemplate.setInterceptors(Collections.singletonList(actionTrackInterceptor));
- restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
- return restTemplate;
- }
-
- @Bean
- public FilterRegistrationBean getFilterRegistrationBean(){
- FilterRegistrationBean bean = new FilterRegistrationBean(new BodyReaderRequestFilter());
- //bean.addUrlPatterns(new String[]{"*.do","*.jsp"});
- bean.addUrlPatterns("/api*");
- return bean;
- }
-
-
- @Override
- protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
- // 错误页面有容器来处理,而不是SpringBoot
- this.setRegisterErrorPageFilter(false);
- builder.properties(PropertiesUtils.getInstance().getProperties());
- return builder.sources(Application.class);
- }
-
- /**
- * 自定义处理Websocket消息队列线程池
- *
- * @return
- */
- @Bean("backExecutor")
- public ThreadPoolTaskExecutor backExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- executor.setThreadNamePrefix("WS-MyExecutor-");
- executor.setCorePoolSize(3);
- executor.setMaxPoolSize(50);
- executor.setQueueCapacity(100);
- executor.setKeepAliveSeconds(300);
- return executor;
- }
-
- @Bean
- public TaskScheduler taskScheduler() {
- ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(3,
- new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build());
- return new ConcurrentTaskScheduler(executorService);
- }
-
- @Bean
- public MultipartConfigElement multipartConfigElement() {
- MultipartConfigFactory factory = new MultipartConfigFactory();
- factory.setMaxFileSize("512MB"); // KB,MB
- factory.setMaxRequestSize("512MB");
- return factory.createMultipartConfig();
- }
-
- @Override
- public void run(String... args) throws Exception {
-
- deviceServiceSupport.putRedisData();
- }
- }
|