package com.softwarebr.nunu;

import com.google.common.collect.Lists;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@SpringBootApplication
@EnableSwagger2
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.brframework", "com.softwarebr.nunu"})
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@EnableScheduling
public class BootNunuApplication {

    public static void main(String[] args) {
        //处理参数
       // args = handlerArgs(args);
        SpringApplication.run(BootNunuApplication.class, args);

    }

    /**
     * 处理参数
     * @param args
     * @return
     */
    private static String[] handlerArgs(String[] args){
        boolean defActive = false;
        for (String arg : args) {
            if(arg.startsWith("--spring.profiles.active=")){
                defActive = true;
                break;
            }
        }

        if(!defActive){
            //默认使用dev启动
            List<String> argList = Lists.newArrayList(args);
            argList.add("--spring.profiles.active=dev");
            args = argList.toArray(new String[]{});
        }

        return args;
    }

}
