268 Star 1.9K Fork 575

GVPdromara / hmily

 / 详情

2.1.1 版本,springcloud jar包内的hmily.yml读取不到,放到user.dir中之后抛异常,不知道着中设计是啥原因

待办的
创建于  
2022-02-21 16:37
public class ServerConfigLoader implements ConfigLoader<HmilyServer> {

    private final YamlPropertyLoader propertyLoader = new YamlPropertyLoader();

    @Override
    public void load(final Supplier<Context> context, final LoaderHandler<HmilyServer> handler) {
        String filePath = System.getProperty("hmily.conf");
        File configFile;
        if (StringUtils.isBlank(filePath)) {
            String dirPath = getDirGlobal();
            configFile = new File(dirPath);
            if (configFile.exists()) {
                filePath = dirPath;
                throw new ConfigException("ConfigLoader:loader config error,error file path:" + filePath);
            } else {
                //Mainly used for development environment。
                ClassLoader loader = ConfigLoader.class.getClassLoader();
                URL url = loader.getResource("hmily.yml");
                if (url != null) {
                    filePath = url.getFile();
                    configFile = new File(filePath);
                } else {
                    throw new ConfigException("ConfigLoader:loader config error,error file path:" + filePath);
                }
            }
        } else {
            configFile = new File(filePath);
            if (!configFile.exists()) {
                throw new ConfigException("ConfigLoader:loader config error,error file path:" + filePath);
            }
        }
        try (FileInputStream inputStream = new FileInputStream(configFile)) {
            List<PropertyKeySource<?>> propertyKeySources = propertyLoader.load(filePath, inputStream);
            OriginalConfigLoader original = new OriginalConfigLoader();
            againLoad(() -> context.get().with(propertyKeySources, original), handler, HmilyServer.class);
        } catch (IOException e) {
            throw new ConfigException("ConfigLoader:loader config error,file path:" + filePath);
        }
    }

    /**
     * Get the current project path.
     *
     * @return Current project path
     */
    private String getDirGlobal() {
        String userDir = System.getProperty("user.dir");
        String fileName = "hmily.yml";
        return String.join(String.valueOf(File.separatorChar), userDir, fileName);
    }
}

问题代码

评论 (0)

李老汉 创建了任务

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
7921160 slipi 1616652133
Java
1
https://gitee.com/dromara/hmily.git
git@gitee.com:dromara/hmily.git
dromara
hmily
hmily

搜索帮助