package com;

import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

@EnableEurekaClient
@EnableDiscoveryClient
@ServletComponentScan
@SpringBootApplication(exclude = PageHelperAutoConfiguration.class)//配置mybatis的配置文件使用，否则报多个分页插件
@MapperScan(basePackages = {"com.chinaitop.depot.**.mapper"})
public class DepotIntelligentApplication {

	public static void main(String[] args) {
		SpringApplication.run(DepotIntelligentApplication.class, args);
	}

	/**
	 * 注册一个dispatcherServlet,解决增加ws之后https接口访问不了问题
	 */
	@Bean
	public ServletRegistrationBean restServlet(){
		//注解扫描上下文
		AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
		//base package
		applicationContext.scan("com.unissoft");
		//通过构造函数指定dispatcherServlet的上下文
		DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext);
		//用ServletRegistrationBean包装servlet
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet);
		registrationBean.setLoadOnStartup(1);
		//指定urlmapping
		registrationBean.addUrlMappings("/*");
		//指定name，如果不指定默认为dispatcherServlet
		registrationBean.setName("rest");
		return registrationBean;
	}

	@Bean
	public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
		return new ThreadPoolTaskScheduler();
	}
}
