‘liusuyi’
2023-07-21 b91fdc439ca1ba0b98409de0f1c0edf6fd626ee9
src/main/java/com/ard/utils/SpringTool.java
@@ -1,9 +1,16 @@
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:
 * @ClassName: SpringTool
@@ -32,4 +39,19 @@
    public static Object getBean(String name) {
        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();
    }
}