package cn.com.qmth.examcloud.core.questions.starter;

import cn.com.qmth.examcloud.web.bootstrap.AppBootstrap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * 项目入口主程序
 */
@EnableJpaAuditing
@EnableEurekaClient
@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan(basePackages = {"cn.com.qmth"})
@EntityScan(basePackages = {"com.qmth.commons", "cn.com.qmth"})
//@EnableJpaRepositories(basePackages = {"cn.com.qmth"}, repositoryBaseClass = BaseQueryDaoImpl.class)
@EnableJpaRepositories(basePackages = {"cn.com.qmth"})
@EnableMongoRepositories("cn.com.qmth.examcloud.core.questions.dao")
@EnableFeignClients(basePackages = {"cn.com.qmth.examcloud.core.questions.service.rpc"})
@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
public class QuestionPoolApplication {

    static {
        String runtimeLevel = System.getProperty("log.commonLevel");
        if (null == runtimeLevel) {
            System.setProperty("log.commonLevel", "DEBUG");
        }
        System.setProperty("hibernate.dialect.storage_engine", "innodb");
    }

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

    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        resolver.setResolveLazily(true);
        resolver.setMaxInMemorySize(40960);
        resolver.setMaxUploadSize(200 * 1024 * 1024);
        return resolver;
    }

}