场景:使用phoenix查询hbase中的数据,解决hbase繁琐的api查询及分页查询很不方便,使用phoenix可以执行sql语句去操作hbase
- 1.引入phoenix的依赖
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.15.0-HBase-1.3</version>
</dependency>
- 2.配置application.properties
spring.datasource.driver-class-name = org.apache.phoenix.jdbc.PhoenixDriver
spring.datasource.url = jdbc:phoenix:node1,node2,node3:2181
spring.datasource.type = com.zaxxer.hikari.HikariDataSource
spring.datasource.username =
spring.datasource.password =
- 3.注入spring管理
/**
* 使用phoenix
*/
@Configuration
public class DataSourceConfig {
@Autowired
private DataSource dataSource;
@Bean(name = "SqlSessionFactory")
public SqlSessionFactory sqlSessionFactory()
throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage("com.qjdchina.ai.service.bigdata.model");
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml"));
return bean.getObject();
}
}
遇到的问题:1.无法创建视图映射HBASE中的表
无法创建视图
解决办法:增加双引号 创建视图映射hbase 查询视图
2.使用mybatis查询提示没找到这张表
表找不到
修改语句,在表名周围加上双引号:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qjdchina.ai.service.bigdata.dao.BlacklistMapper">
<select id="queryAll" resultType="BlackList">
select * from "blacklist"
</select>
</mapper>
网友评论