导读
本文主要是pom文件的条用,
明白配置完毕,如何调用即可?
这几天一直在纠结spring-data-hadoop的JAR包,总是运行不成功,现在终于可以运行了,pom内容为:
复制代码
spring配置文件为:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/hadoop"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd"
default-autowire="byName">
<context:property-placeholder location="classpath:config.properties" />
<configuration>
fs.default.name=${hd.fs}
mapred.job.tracker=${hd.mr}
</configuration>
<!-- This will throw a NPE at the end of running the app that should be ignored
To avoid this, run against the stand-alone server, use the command line
hive -hiveconf fs.default.name=hdfs://localhost:9000 -hiveconf mapred.job.tracker=localhost:9001
-->
<hive-server port="${hive.port}" auto-startup="true"/>
<hive-client-factory host="${hive.host}" port="${hive.port}"/>
<hive-template id="hiveTemplate"/>
</beans:beans>
复制代码
参数配置文件为:
hd.fs=hdfs://172.16.1.50:8020
hd.mr=172.16.1.50:8021
hd.zk.port=2181
hd.zk.host=172.16.1.50
hive.host=172.16.1.50
hive.port=10000
程序中调用方式:
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
HiveTemplate hiveTemplate = (HiveTemplate) ac.getBean("hiveTemplate");
List list = hiveTemplate.query("show tables;");
System.out.println(JSON.toJSONString(list));
调用成功