WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
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
package tech.powerjob.server.common.utils;
 
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
 
import java.io.InputStream;
import java.net.URL;
import java.util.Objects;
import java.util.Properties;
 
/**
 * 加载配置文件
 *
 * @author tjq
 * @since 2020/5/18
 */
@Slf4j
public class PropertyUtils {
 
    private static final Properties PROPERTIES = new Properties();
 
    public static Properties getProperties() {
        return PROPERTIES;
    }
 
    public static void init() {
        URL propertiesURL =PropertyUtils.class.getClassLoader().getResource("application.properties");
        Objects.requireNonNull(propertiesURL);
        try (InputStream is = propertiesURL.openStream()) {
            PROPERTIES.load(is);
        }catch (Exception e) {
            ExceptionUtils.rethrow(e);
        }
    }
}