FeoJobApplication.java 2.11 KB
Newer Older
xd's avatar
xd committed
1 2
package com.tanpu.feo.feojob;

吴泽佳's avatar
吴泽佳 committed
3 4
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.extern.slf4j.Slf4j;
xd's avatar
xd committed
5
import org.mybatis.spring.annotation.MapperScan;
吴泽佳's avatar
吴泽佳 committed
6 7
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
xd's avatar
xd committed
8 9
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
吴泽佳's avatar
吴泽佳 committed
10 11 12 13 14 15
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
xd's avatar
xd committed
16 17

@SpringBootApplication
吴泽佳's avatar
吴泽佳 committed
18 19 20 21 22 23 24 25 26 27
@MapperScan(basePackages = "com.tanpu.feo.**.mapper")
@Slf4j
@EnableScheduling //开启定时任务
public class FeoJobApplication implements CommandLineRunner {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private Environment env;
xd's avatar
xd committed
28 29 30 31 32

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

吴泽佳's avatar
吴泽佳 committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    @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);
        }
    }

xd's avatar
xd committed
55
}