package com.crunii.micro.gateway;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.crunii.micro.common.config.SwaggerConfiguration;
import com.crunii.micro.common.config.SwaggerConflictFixConfiguration;
import com.crunii.micro.common.utils.JasyptEncryptorUtil;
import com.crunii.micro.common.utils.LogPathUtil;
import com.crunii.micro.gateway.config.GatewayGrayLoadBalancedConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.ImportResource;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.util.StringUtils;

/**
 * @author 田平 create 2022-06-08 02:12:36
 */

@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@EnableCaching
@ImportResource({ "classpath:spring/*.xml" })
@SpringBootApplication(
		exclude = {
				SwaggerConfiguration.class,
				SwaggerConflictFixConfiguration.class,
				RedisAutoConfiguration.class,
				RedisReactiveAutoConfiguration.class,
				TransactionAutoConfiguration.class,
				DataSourceAutoConfiguration.class,
				DruidDataSourceAutoConfigure.class,
				HibernateJpaAutoConfiguration.class
		})
@LoadBalancerClients(defaultConfiguration = GatewayGrayLoadBalancedConfiguration.class)
public class Application {

	public static void main(String[] args) {
		JasyptEncryptorUtil.setConfigClientProps();
		JasyptEncryptorUtil.setAdminClientProps();
		// 接netty重复设置的问题
		System.setProperty("es.set.netty.runtime.available.processors", "false");

		String env = System.getProperty("spring.profiles.active");
		if (!StringUtils.hasText(env)) {
			// local or dev or prod
			env = "dev";
			System.setProperty("spring.profiles.active", env);
			// 设置nacos的日志目录
			System.setProperty("nacos.logging.path", LogPathUtil.getNacosLogPath());
		}
		SpringApplication.run(Application.class, args);
	}

}
