Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate query data by Hbase+Phoenix+Mybatis+Springboot

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how Hbase+Phoenix+Mybatis+Springboot integrates query data, the content is very detailed, interested friends can use it for reference, I hope it can be helpful to you.

Phoenix Query Server provides an alternative way to interact with Phoenix and HBase. Soon, this will allow access from environments other than JVM.

In versions 4.x and 5.0, the query server and its JDBC client are part of the standard Phoenix distribution. They do not require other dependencies.

After version 5. 0, the query server was bundled into the phoenix-queryserver repository and its version number was reset to 1. 0. At the time of this writing, there is no release version of the independent query server.

Since we installed apache-phoenix-5.0.0-HBase-2.0, queryserver is built into it.

1. Start queryserver and listen to 8765 by default

> apache-phoenix-5.0.0-HBase-2.0-bin/bin/queryserver.py

two。 Custom configuration vim hbase-site.xml

Property describes the default phoenix.queryserver.http.port specifies the port on which the server will listen. The default value is 8765. The Avatica Meta.Factory class to be instantiated by 8765phoenix.queryserver.metafactory.class. Org.apache.phoenix.queryserver.server.PhoenixMetaFactoryImplphoenix.queryserver.serialization transport / serialization format, PROTOBUF or JSON. PROTOBUF// changed the default port 8765 to 8888 phoenix\ .queryserver\ .http\ .port 8888

Introducing Phoenix client into 3.pom.xml

/ / lightweight client org.apache.phoenix phoenix-queryserver-client 5.0.0-HBase-2.0

4. Complete pom.xml

4.0.0 com.rumenz phoenix 0.0.1-SNAPSHOT phoenix Demo project for Spring Boot 1.8 UTF-8 UTF-8 2.3.0.RELEASE org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime Org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.mybatis.spring.boot mybatis-spring-boot- Starter 2.1.0 org.apache.phoenix phoenix-queryserver-client 5.0.0-HBase-2.0 com.alibaba druid 1.1.21 org.springframework.boot Spring-boot-dependencies ${spring-boot.version} pom import org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 1.8 UTF-8 org.springframework.boot spring-boot-maven-plugin 2.3.0.RELEASE com.rumenz.phoenix.PhoenixApplication Repackage repackage

5. Data source configuration

Package com.rumenz.phoenix;import com.alibaba.druid.pool.DruidDataSource;import org.apache.phoenix.queryserver.client.Driver;import org.mybatis.spring.annotation.MapperScan;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import javax.sql.DataSource;@Configuration@MapperScan (basePackages = "com.rumenz.phoenix.mapper") public class PhoenixForMybatisConfiguration {@ Autowired private DataSourceProperties dataSourceProperties @ Bean public DataSource phoenixDataSource () {DruidDataSource druidDataSource = new DruidDataSource (); / / set Phoenix driver druidDataSource.setDriverClassName (Driver.class.getName ()); druidDataSource.setUrl (dataSourceProperties.getUrl ()); return druidDataSource;}}

6. Database operation class UserMapper

Note: because my HBase database table name and field name are lowercase, I must add double quotation marks to the table name and field name, otherwise the table name and field name will become uppercase, no corresponding relationship can be found, and an error will be reported.

If both table and field names are uppercase in the HBase database, double quotation marks are not required

Package com.rumenz.phoenix.mapper;import com.rumenz.phoenix.entity.User;import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Select;@Mapperpublic interface UserMapper {/ / Table and field names must be enclosed in double quotation marks, otherwise the table and field names will become uppercase and no corresponding relationship will be found, and an error @ Select ("select * from\" test2\ "where\" id\ "= # {id}") User selectById (Integer id) will be reported;}

7. Entity class

Package com.rumenz.phoenix.entity;public class User {private Integer id; private String name; private Integer age; public Integer getId () {return id;} public void setId (Integer id) {this.id = id;} public String getName () {return name;} public void setName (String name) {this.name = name } public Integer getAge () {return age;} public void setAge (Integer age) {this.age = age;} @ Override public String toString () {return "User {" + "id=" + id + ", name='" + name +'\'+ ", age=" + age +'}' }}

8. Access control UserController

Package com.rumenz.phoenix.controller;import com.rumenz.phoenix.entity.User;import com.rumenz.phoenix.mapper.UserMapper;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping ("/ user/") public class UserController {@ Autowired private UserMapper userMapper GetMapping ("index") public String index () {User user = userMapper.selectById (1); return user.toString ();}}

9. Visit http://127.0.0.1:8080/user/index

User {id=1, name='rumenz', age=30} on how to integrate Hbase+Phoenix+Mybatis+Springboot query data sharing here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report