Application.java
2.62 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
59
60
61
62
63
64
65
66
67
68
69
package com.bsth;
import com.bsth.util.AppProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.core.env.ConfigurableEnvironment;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(10);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
boolean normal = false;
for (String arg : arguments) {
if (arg.indexOf("-XX:+DisableAttachMechanism") > -1) {
normal = true;
break;
}
}
if (normal) {
loadProperties();
SpringApplication.run(Application.class, args);
}
}
private static void loadProperties() {
Properties prop = new Properties();
try (InputStream input = Application.class.getClassLoader().getResourceAsStream("application.properties")) {
prop.load(input);
String activeProfile = prop.getProperty("spring.profiles.active", "");
String cacheDays = prop.getProperty("cache.days", "15");
InputStream input1 = Application.class.getClassLoader().getResourceAsStream(String.format("application-%s.properties", activeProfile));
prop.load(input1);
String controlUrl = prop.getProperty("http.control.service_data_url", "");
String secretKey = prop.getProperty("http.control.secret.key", "");
String gpsUrl = prop.getProperty("http.gps.real.url", "");
AppProperties.setCacheDays(Integer.parseInt(cacheDays));
AppProperties.setControlUrl(controlUrl);
AppProperties.setSecretKey(secretKey);
AppProperties.setGpsUrl(gpsUrl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}