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

时间:2022-11-10 13:01:08

【特别注意】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的时候报错:
Sqoop2中传入配置文件中url之【坑】

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

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

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