MoonLord-LM / MyJava

MyJava
2 stars 2 forks source link

获取 Spring 配置信息 #306

Open MoonLord-LM opened 7 months ago

MoonLord-LM commented 7 months ago
/**
 * 获取 Spring 配置信息
 */
public static String getSpringConfig(String configKey) {
    try {
        Object bean = SpringContextUtil.getBean("environment");
        if (bean instanceof Environment) {
            Environment environment = (Environment) bean;
            return environment.getProperty(configKey);
        }
    }
    catch (Exception e) {
        logger.error("error", e);
    }
    return null;
}