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 未初始化"); } } }