Helius
2022-03-10 70ccc6d4225d2cb85244d5e2dca3949f6677707c
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
package com.matrix.core.tools;
 
import com.matrix.core.exception.GlobleException;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
 
@Component
public class EnvironmentHolder implements EnvironmentAware {
 
 
    private static Environment env;
 
 
    @Override
    public void setEnvironment(Environment environment) {
        env = environment;
    }
 
    /**
     * 获取配置文件中的值
     * @param key
     * @return
     */
    public static String getPropertis(String key) {
        if (env != null) {
            return env.getProperty(key);
        } else {
            throw new GlobleException("Environment 未初始化");
        }
    }
 
}