-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigLoader.java
More file actions
33 lines (28 loc) · 930 Bytes
/
ConfigLoader.java
File metadata and controls
33 lines (28 loc) · 930 Bytes
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
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @author chake
*/
public class ConfigLoader {
private static final Properties PROPS = new Properties();
static {
try (InputStream input = ConfigLoader.class.getClassLoader().getResourceAsStream("config.properties")) {
if (input == null) {
throw new RuntimeException("配置文件 config.properties 未找到!");
}
PROPS.load(input);
} catch (IOException e) {
throw new RuntimeException("加载配置文件失败", e);
}
}
public static String getDbUrl() {
return PROPS.getProperty("db.url");
}
public static String getDbUser() {
return PROPS.getProperty("db.user");
}
public static String getDbPassword() {
return PROPS.getProperty("db.password");
}
}