本帖最后由 howtodown 于 2014-11-15 12:53 编辑
问题导读
1.maven的pom文件该如何配置?
2.spring配置文件需要哪些改变?
这几天一直在纠结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));
复制代码
调用成功
|