Sqoop2中传入配置文件中url之【坑】

【特别注意】Sqoop2里面各个版本的区别还是很大的,这里使用1.99.6版本。

  • sqoop2的url等信息放到properties配置文件中,配置文件解析出来传给SqoopClient报错。

SqoopClient初始化代码:

    private SqoopUtil() throws IOException {

        String url = PropertiesUtil.getProperty("SQOOP_URL").trim();
        SqoopClient client = new SqoopClient(url);
        System.out.println("url:" +url);
        connectorMap = new HashMap<String, Long>();
        System.out.println(client.getConnector(2));//注释掉该句不报错
    //  readConnectorMap();
        System.out.println("connectorMap size---------"+ connectorMap.size());

    }

配置文件解析工具类,解析/myconf.properties文件。

public class PropertiesUtil {

    private static String propertiesFile = "/myconf.properties";
    private static PropertiesUtil proUtil = null;
    private static HashMap<String, String> confMap= null;
    private static Properties p = new Properties();

    public PropertiesUtil() throws IOException {
        confMap = new HashMap<String, String>();
        readPropertiesToMap();
        System.out.println();
    }

    private static void readPropertiesToMap() throws IOException {

        p.load(PropertiesUtil.class.getResourceAsStream(propertiesFile));

        for(Object key: p.keySet()) {
            confMap.put((String)key, p.getProperty((String)key));
        }
    }

    private static PropertiesUtil getPropertiesUtil() throws IOException {

        if(proUtil == null) {
            synchronized(PropertiesUtil.class) {
                if(proUtil == null) {
                    long start = System.currentTimeMillis();
                    proUtil = new PropertiesUtil();
                    long end = System.currentTimeMillis();
                    System.out.println("construct properties util last "+ (end-start));
                }
            }
        }

        return proUtil;
    }


    public String get(String name) throws IOException {
        return confMap.get(name);
    }
    public static String getProperty(String name) throws IOException {

        return getPropertiesUtil().confMap.get(name);
    }

    public static void main(String[] args) throws IOException {
        System.out.println(getPropertiesUtil().confMap.get("SQOOP_URL"));
    }

}

但在调用client.getConnector的时候报错:
这里写图片描述

将初始化SqoopClient的url改为/myconf.properties文件中的SQOOP_URL对应的字符串则能顺利运行:

这里写图片描述

暂时还没解决。。。正在研究中。。。

 

转载于:https://www.cnblogs.com/eva_sj/p/6172244.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值