package com.uas.finance;

import com.uas.finance.util.ContextUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.ImportResource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

/**
 * created by shicr on 2017/12/12
 **/
@EnableTransactionManagement(proxyTargetClass = true)
@SpringBootApplication(scanBasePackages = "com.uas.finance")
@EnableWebMvc
@ImportResource("classpath:spring/*.xml")
public class Application {
    public static void main(String[] args) throws FileNotFoundException {
        File logFile = new File("logs/log.log");
        if (!logFile.getParentFile().exists()) {
            logFile.getParentFile().mkdir();
        }
        System.setErr(new PrintStream(new FileOutputStream(logFile, true)));
        SpringApplication application = new SpringApplication(Application.class);
        application.addListeners(new ApplicationListener<ApplicationPreparedEvent>() {
            @Override
            public void onApplicationEvent(ApplicationPreparedEvent event) {
                ContextUtils.setApplicationContext(event.getApplicationContext());
            }
        });
        application.run(args);
    }
}
