RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Hbase+Phoenix+Mybatis+Springboot如何进行整合查询数据

这篇文章给大家介绍Hbase+Phoenix+Mybatis+Springboot如何进行整合查询数据,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

创新互联公司网站建设公司一直秉承“诚信做人,踏实做事”的原则,不欺瞒客户,是我们最起码的底线! 以服务为基础,以质量求生存,以技术求发展,成交一个客户多一个朋友!专注中小微企业官网定制,做网站、成都网站建设,塑造企业网络形象打造互联网企业效应。

Phoenix Query Server提供了一种与Phoenix和HBase交互的替代方法。很快,这将允许从JVM以外的环境进行访问。

  • 在4.x和5.0版本中,查询服务器及其JDBC客户端是标准Phoenix发行版的一部分。它们不需要其他依赖项。

  • 在5.0版本之后,查询服务器已被捆绑到phoenix-queryserver存储库中,并且其版本号已重置为1.0。在撰写本文时,没有独立查询服务器的发行版本。

由于我们安装的是apache-phoenix-5.0.0-HBase-2.0,所以里面内置了queryserver

1.启动queryserver,默认监听8765

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

2.自定义配置 vim hbase-site.xml

属性描述默认
phoenix.queryserver.http.port指定服务器将侦听的端口。默认值为8765。8765
phoenix.queryserver.metafactory.class要实例化的Avatica Meta.Factory类。org.apache.phoenix.queryserver.server.PhoenixMetaFactoryImpl
phoenix.queryserver.serialization传输/序列化格式,PROTOBUF或JSON。PROTOBUF
//将默认的8765端口改成8888

  phoenix\.queryserver\.http\.port
  8888

3.pom.xml中引入Phoenix客户端

//轻量级客户端

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

4.完整的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.数据源配置

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();
        //设置Phoenix驱动
        druidDataSource.setDriverClassName(Driver.class.getName());
        druidDataSource.setUrl(dataSourceProperties.getUrl());
        return druidDataSource;
    }
}

6.数据库操作类UserMapper

注意:由于我的HBase数据库表名和字段名都是小写所以我这里表名和字段名必须加上双引号,否则表名和字段名会变成大写,找不到对应关系,会报错。

如果HBase数据库中表名和字段名都是大写,那么则不需要双引号

package com.rumenz.phoenix.mapper;

import com.rumenz.phoenix.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {
    //表名和字段名必须加上双引号,否则表名和字段名会变成大写,找不到对应关系,会报错
    @Select("select * from \"test2\" where \"id\"=#{id}")
    User selectById(Integer id);
}

7.实体类

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.访问控制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.访问http://127.0.0.1:8080/user/index

User{id=1, name='rumenz', age=30}

关于Hbase+Phoenix+Mybatis+Springboot如何进行整合查询数据就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


文章名称:Hbase+Phoenix+Mybatis+Springboot如何进行整合查询数据
网址分享:http://scyingshan.cn/article/pjocje.html