935090232@qq.com
2022-02-24 8c6026959d3006bbf9dce3f3c9311e70a02b80c1
zq-erp/src/main/java/com/matrix/core/tools/EnvironmentHolder.java
New file
@@ -0,0 +1,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 未初始化");
        }
    }
}