package org.nl.acs.utils;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.util.Properties;

/**
 * @Author: lyd
 * @Description: 配置文件获取方法
 * @Date: 2023/12/6
 */
public class YmlConfigFileUtil {
    public static Properties readConfig(String configFile) {
        // 创建 Resource 对象
        Resource resource = new ClassPathResource(configFile);

        // 创建 YamlPropertiesFactoryBean
        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(resource);

        // 获取 Properties 对象
        Properties properties = yamlPropertiesFactoryBean.getObject();

        return properties;
    }
}
