FeoJobApplication.java 2.54 KB
package com.tanpu.feo.feojob;


import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix
@EnableFeignClients
@EnableTransactionManagement
//@MapperScan(basePackages = "com.tanpu.feo.**.mapper")
@ComponentScan({"com.tanpu.common","com.tanpu.feo.feojob"})
@Slf4j
@EnableScheduling //开启定时任务
public class FeoJobApplication implements CommandLineRunner {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private Environment env;

    public static void main(String[] args) {
        SpringApplication.run(FeoJobApplication.class, args);
    }

    @Override
    public void run(String... args) {
        try (Connection conn = dataSource.getConnection()) {
            String SERVER_PORT = env.getProperty("server.port");
            String SYSTEM_NAME = env.getProperty("server.servlet.context-path");
            // 这里,可以做点什么
//        	log.info("[run][获得连接:{}]", conn);
            log.info("\n--------------------------------------------------------------------------------------------------------------------\n\t" +
                            "数据库链接:{}\n\t" +
                            "Application '{}' is running! Access URLs:\n\t" +
                            "Local: \t\t\thttp://127.0.0.1:{}\n\t" +
                            "Swagger url: \thttp://localhost:{}{}/doc.html\n--------------------------------------------------------------------------------------------------------------------",
                    conn,
                    SYSTEM_NAME,
                    SERVER_PORT,
                    SERVER_PORT,
                    SYSTEM_NAME);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

}