flink 读取resource配置返回null

问题

以下代码在本机可以, docker环境下跑不行
测试服务器表现为无法正常读取资源文件,返回的是null
flink 读取resource配置返回null_第1张图片

解决

分析,服务器多线程环境,需要获取当前线程的 ClassLoader

 public static Properties getPom() {
        Properties pom = new Properties();
        try {
            // 获取当前线程的 ClassLoader
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            InputStream inputStream = classLoader.getResourceAsStream("pom.properties.template");
            pom.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pom;
    }

你可能感兴趣的:(flink,java,数据库)