|
Srping对于属于java web技术的程序员都不会陌生,jdbcTemplate更是用的熟之又熟,下面我们来认识一下Spring大家庭的新成员:Spring-data-hadoop项目。Spring-hadoop这个项目应该是在Spring Data项目的一部分(Srping data其余还包括把Spring和JDBC,REST,主流的NoSQL结合起来了)。其实再一想,Spring和Hadoop结合会发生什么呢,其实就是把Hadoop组件的配置,任务部署之类的东西都统一到Spring的bean管理里去了。
具体操作如下:
1、下载并导入需要的jar包:
2、配置web.xml:
1
2
5
6 contextConfigLocation
7 classpath:beans.xml
8
9
10
11
12 org.springframework.web.context.ContextLoaderListener
13
14
15
16 org.springframework.web.util.IntrospectorCleanupListener
17
18
19
20 login.jsp
21
22
3、配置beans.xml:
1
2
14
15
16
17
18
19
20
21
22
23
24
4、将hbase-site.xml配置文件拷贝到src目录下,参考内容如下:
1
2
3
4 hbase.rootdir
5 hdfs://nameservice1/hbase
6
7
8 hbase.client.write.buffer
9 62914560
10
11
12 hbase.client.pause
13 1000
14
15
16 hbase.client.retries.number
17 10
18
19
20 hbase.client.scanner.caching
21 1
22
23
24 hbase.client.keyvalue.maxsize
25 62914560
26
27
28 hbase.rpc.timeout
29 60000
30
31
32 hbase.security.authentication
33 simple
34
35
36 zookeeper.session.timeout
37 60000
38
39
40 zookeeper.znode.parent
41 /hbase
42
43
44 zookeeper.znode.rootserver
45 root-region-server
46
47
48 hbase.zookeeper.quorum
49 xinhong-hadoop-56,xinhong-hadoop-52,xinhong-hadoop-53
50
51
52 hbase.zookeeper.property.clientPort
53 2181
54
55
5、hbase模板的demo:
查询列族下的列的数据:
1 public List find(String tableName,String family,String cloumn){
2 List rows = hbaseTemplate.find(tableName, family,cloumn, new RowMapper() {
3 public String mapRow(Result result, int rowNum) throws Exception {
4 return Bytes.toString(result.getRow());
5 }
6 });
7 return rows;
8 }
查询指定行健的一列数据:
1 public String get(String tableName,String family,String cloumn,String rowKey){
2 String context = hbaseTemplate.get(tableName, "NCEP_p_wa_2014032212_tp_006.nc", family, cloumn, new RowMapper() {
3 public String mapRow(Result result, int rowNum) throws Exception {
4 return Bytes.toString(result.value());
5 }
6 });
7 return context;
8 }
PS:其中RowMapper回调函数的使用方法可以参考http://www.iyunv.com/zhangyukun/p/3685369.html来使用,用法大致相同。 |
|
|