package cn.com.capcloud;

import org.modelmapper.ModelMapper;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.net.InetAddress;

/**
 * 启动类
 */
@ServletComponentScan
@EnableScheduling
@EnableAsync
@EnableWebMvc
@SpringBootApplication(exclude = {
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class App {

  private static final org.slf4j.Logger logger = LoggerFactory.getLogger(App.class);

  public static void main(String[] args) {
    try {
      ConfigurableApplicationContext context= SpringApplication.run(App.class, args);
      ConfigurableEnvironment environment = context.getEnvironment();
      String hostAddress = InetAddress.getLocalHost().getHostAddress();
      String port = environment.getProperty("server.port");
      String contextPath = environment.getProperty("server.servlet.context-path");
      logger.info("启动成功，接口地址为：http://"+hostAddress+":"+port+contextPath);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  @Bean
  public ModelMapper modelMapper() {
    return new ModelMapper();
  }
}
