ControlManagerCenterApplication.java
2.67 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
51
52
53
54
55
56
57
58
package com.huaheng.control.management;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@SpringBootApplication
public class ControlManagerCenterApplication {
public static void main(String[] args) {
ConfigurableApplicationContext application = SpringApplication.run(ControlManagerCenterApplication.class, args);
Environment env = application.getEnvironment();
String ip = getLocalHostExactAddress().getHostAddress();
String port = env.getProperty("server.port");
String profiles = env.getProperty("spring.profiles.active");
String path = env.getProperty("server.servlet.context-path");
log.info("\n----------------------------------------------------------------------------------\n\n\t"
+ "Application Huaheng Control Management Center is running!\n\n\t"
+ "WEB swagger local: \t\thttp://localhost:" + port + path + "/swagger-ui/index.html\n\t"
+ "WEB swagger external: \thttp://" + ip + ":" + port + path + "/swagger-ui/index.html\n\n\t"
+ "The following profiles are active: [" + profiles + "]\n\n"
+ "-----------------------------------------------------------------------------------");
}
public static InetAddress getLocalHostExactAddress() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface netInterface = networkInterfaces.nextElement();
// System.out.println(netInterface.getName());
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress ipTmp = addresses.nextElement();
if (ipTmp != null && ipTmp instanceof Inet4Address && ipTmp.isSiteLocalAddress() && !ipTmp.isLoopbackAddress()
&& ipTmp.getHostAddress().indexOf(":") == -1 && !ipTmp.getHostAddress().endsWith(".1")) {
return ipTmp;
}
}
}
return InetAddress.getLocalHost();
} catch (SocketException | UnknownHostException e) {
e.printStackTrace();
}
return null;
}
}