1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}
}
}