package com.netwisd.base.main;

import cn.hutool.core.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import java.net.Inet4Address;

@SpringBootApplication
@EnableConfigurationProperties
@EnableAsync
@EnableFeignClients
public class MainApplication {
    public static void main(String[] args) {
        String startTime = DateUtil.now();
        Logger log = LoggerFactory.getLogger(MainApplication.class);
        ConfigurableApplicationContext context = SpringApplication.run(MainApplication.class);
        try {
            //ip
            String hostAddress = Inet4Address.getLocalHost().getHostAddress();
            //获取端口
            String port = context.getBean(Environment.class).getProperty("server.port");
            String ip = "http://" + hostAddress + ":" + port + "/swagger-ui.html";
            log.info(ip);
            String doc = "http://" + hostAddress + ":" + port + "/doc.html";
            log.info(doc);
            log.info("Main启动了,启动开始时间:{}，启动结束时间:{}", startTime, DateUtil.now());
        } catch (Exception e) {
            log.error("启动失败:", e);
        }
    }
}