GarbageApplication.java
2.03 KB
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
package com.trash.garbage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author trash
*/
@SpringBootApplication
@EnableAsync
@Slf4j
public class GarbageApplication {
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext run = SpringApplication.run(GarbageApplication.class, args);
ConfigurableEnvironment env = run.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
String redisPort = env.getProperty("spring.redis.port");
String redisHost = env.getProperty("spring.redis.host");
String sqlUrl = env.getProperty("spring.datasource.druid.url");
List<String> sqlInfo = getSqlInfo(sqlUrl);
log.info(
"\n Swagger访问地址:http://" + ip + ":" + port + path + "/doc.html \n" +
" Redis服务器地址:" + redisHost + ":" + redisPort + "\n" +
" Mysql服务器地址:" + sqlInfo.get(0) + ":" + sqlInfo.get(1));
log.info("--装修垃圾服务启动成功 --");
}
private static List<String> getSqlInfo(String sqlInfo) {
List<String> str = new ArrayList<>(3);
Pattern pattern = Pattern.compile("jdbc:mysql://([a-zA-Z0-9.-]+):(\\d+)/");
Matcher matcher = pattern.matcher(sqlInfo);
if (matcher.find()) {
str.add(matcher.group(1));
str.add(matcher.group(2));
}
return str;
}
}