‘liusuyi’
2023-07-05 1fd64b07ddb99c2d9cc8a358b71aceb6a2c81492
src/main/java/com/ard/utils/SpringTool.java
@@ -1,11 +1,15 @@
package com.ard.utils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import java.nio.ByteBuffer;
import java.util.Properties;
/**
 * @Description:
@@ -36,4 +40,18 @@
        return getApplicationContext().getBean(name);
    }
    /*yml配置信息获取*/
    public static String getYmlInfo(String key) {
        Resource resource = new ClassPathResource("application.yml");
        Properties properties = null;
        try {
            YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
            yamlFactory.setResources(resource);
            properties = yamlFactory.getObject();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return properties.get(key).toString();
    }
}