1. Environment Preparation:
Maven
Eclipse
Java
Spring version 3..2.9
2. Maven pom.xml Configuration
<!--Spring Hadoop--- <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>0.96.1.1-hadoop2</version> < /dependency><dependency><groupid>org.springframework.data</groupid><artifactid> Spring-data-jpa</artifactid><version>1.6.0.release</version></dependency> < dependency> <groupId>org.springframework.data</groupId> <artifactId> spring-data-hadoop</artifactid> <version>2.0.2.RELEASE</version> </dependency>
3. Spring and Hadoop, hbase related configuration files
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc= "Http://www.springframework.org/schema/jdbc" Xmlns:tx = "Http://www.springframework.org/schema/tx" xmlns:util= "Http://www.springframework.org/schema/util" xmlns:aop= " Http://www.springframework.org/schema/aop "xmlns:context=" Http://www.springframework.org/schema/context "xmlns: mongo= "Http://www.springframework.org/schema/data/mongo"xmlns:hdp= "Http://www.springframework.org/schema/hadoop"Xmlns:cache= "Http://www.springframework.org/schema/cache" xmlns:c= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/C" xmlns:p= "http://www.springframework.org/schema/p" xsi:schemalocation= "http://www.springframework.org/schema/ JDBC Http://www.springframework.org/schema/jdbc/spring-jdbc.xsd Http://www.springframework.org/schema/beans http: Www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/util HTTP://WWW.SP Ringframework.org/schema/util/spring-util.xsd Http://www.springframework.org/schema/tx Http://www.springframewor K.org/schema/tx/spring-tx.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/ao P/spring-aop.xsd Http://www.springframework.org/schema/data/mongo Http://www.springframework.org/schema/data/mon Go/spring-mongo.xsdHttp://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd Http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd ">
Where red is the spring Hadoop XML namespace configuration.
Hadoop hbase The relevant configuration files are as follows:
<!--default Properties-->
HDFs://192.98.8.224:8010
"${delete-connection}" zk-quorum="${ Hbase.zookeeper.quorum} "zk-port=" ${hbase.zookeeper.property.clientport} "/>
the corresponding properties as follows:
hbase.zookeeper.property.clientport=2181
hbase.zookeeper.quorum=192.98.8.224
hbase.master=192.98.8.224:600000
Fs.default.name=HDFs://192.98.8.224:8010
Delete-connection=true
#hive jdbc URL
Hive.url=jdbc:hive://192.98.8.224:10000/default
Spring Hbasetemplate The configuration is as follows:
<bean id="hbasetemplate" class="Org.springframework.data.hadoop.hbase.HbaseTemplate"> <property name="Configuration" ref="hbaseconfiguration" />
</bean>
Hbasetemplate Using code Examples:
Tile t = hbasetemplate.get ("Gw_tiles", "0_1_1", new Rowmapper<tile> () {@Overridepublic tile maprow (result result, I NT RowNum) throws Exception {//TODO auto-generated method Stubtile t = new Tile (); T.setdata (Result.getvalue ("T". GetBytes ( ), "Key". GetBytes ())); return t;});
hbasetemplate Introduction to Common methods:
Hbasetemplate.get ("Gw_tiles", "0_1_1", new rowmapper are commonly used for queries, as shown in the following example:
Tile t = hbasetemplate.get ("Gw_tiles", "0_1_1", new Rowmapper<tile> () {@Overridepublic tile maprow (result result, I NT RowNum) throws Exception {//TODO auto-generated method Stubtile t = new Tile (); T.setdata (Result.getvalue ("T". GetBytes ( ), "Key". GetBytes ())); return t;});
Hbasetemplate.execute (Dataidentifier, new tablecallback is commonly used for update operations, as shown in the following example:
Return Hbasetemplate.execute (Dataidentifier, New tablecallback<boolean> () {@Overridepublic Boolean dointable ( Htableinterface table) throws Throwable {//TODO auto-generated method Stubboolean flag = false;try{delete Delete = new De Lete (Key.getbytes ()); Table.delete (delete); flag = true;} catch (Exception e) {e.printstacktrace ();} return flag;});
Note : Spring Hbasetemplate is a powerful package for hbase interfaces, with common functionality that uses its powerful interfaces, while complex functions can also use hbase native interfaces such as: Htableinterface, Result and so on. Its class methods are as follows:
At the same time, Hbasetemplate encapsulates the HBase connection pool, and its creation and release is automatically managed through configuration.
Article reproduced please specify the source: http://www.cnblogs.com/likehua/p/4016257.html
Spring Hadoop access to HBase Getting Started