springboot连接hive数据库

springboot连接hive数据库springboot 后台开发连接 hive 数据库确保集群上 hivesever2 的服务已启动 hive 数据库一般在 10000 端口 springboot 开发 pox xml 文件 xmlversion 1 0 encoding UTF 8

springboot后台开发连接hive数据

确保集群上hivesever2的服务已启动

hive数据库一般在10000端口

springboot开发

  • pox.xml 文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.education</groupId> <artifactId>edu_server</artifactId> <version>0.0.1-SNAPSHOT</version> <name>edu_server</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.1.2.RELEASE</version> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> <version>2.1.2.RELEASE</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-hadoop</artifactId> <version>2.5.0.RELEASE</version> <exclusions> <exclusion> <groupId>jdk.tools</groupId> <artifactId>jdk.tools</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version>1.1.0</version> <exclusions> <exclusion> <groupId>org.eclipse.jetty.aggregate</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>jdk.tools</groupId> <artifactId>jdk.tools</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>org.apache.hive</groupId> <artifactId>hive-shims</artifactId> </exclusion> <exclusion> <artifactId>jasper-compiler</artifactId> <groupId>tomcat</groupId> </exclusion> <exclusion> <artifactId>jasper-runtime</artifactId> <groupId>tomcat</groupId> </exclusion> <exclusion> <artifactId>servlet-api</artifactId> <groupId>javax.servlet</groupId> </exclusion> <exclusion> <artifactId>log4j-slf4j-impl</artifactId> <groupId>org.apache.logging.log4j</groupId> </exclusion> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> <exclusion> <groupId>tomcat</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </exclusion> <exclusion> <groupId>org.eclipse.jetty.orbit</groupId> <artifactId>*</artifactId> </exclusion> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>org.mortbay.jetty</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> <version>9.0.11</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 
  • application.yml文件
server: port: 18891 hive: url: jdbc:hive2://10.100.XX.XXX:10000/default #hive默认数据库 driver-class-name: org.apache.hive.jdbc.HiveDriver type: com.alibaba.druid.pool.DruidDataSource user: a password: b initialSize: 1 minIdle: 3 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 30000 validationQuery: select 1 testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 
  • hive配置
package com.education.edu_server.config; import org.apache.tomcat.jdbc.pool.DataSource; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; @Configuration public class HiveConfig { 
    @Value("${hive.url}") private String url; @Value("${hive.driver-class-name}") private String driver; @Value("${hive.user}") private String user; @Value("${hive.password}") private String password; @Bean public DataSource dataSource(){ 
    DataSource dataSource = new DataSource(); dataSource.setUrl(url); dataSource.setDriverClassName(driver); dataSource.setUsername(user); dataSource.setPassword(password); return dataSource; } @Bean public JdbcTemplate jdbcTemplate(DataSource dataSource){ 
    return new JdbcTemplate(dataSource); } } 
  • controller
package com.education.edu_server.controller; import com.alibaba.fastjson.JSON; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @RestController @RequestMapping("/index") public class IndexController { 
    @Autowired @Qualifier("jdbcTemplate") private JdbcTemplate jdbcTemplate; @GetMapping("/list") public String list() { 
    String sql = "select app,pref from game_pref order by pref desc"; List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); return JSON.toJSONString(list); } } 

注意事项(坑)

  1. Error: Could not open client transport with JDBC Uri:
    hive地址不对,询问管理hive集群的人解决

  2. Required field ‘client_protocol’ is unset!
    jdbc-hive依赖的版本(2.3.3)与hive的版本(1.1.0)不匹配,将jdbc-hive依赖版本改为1.1.0

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217032.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 上午10:30
下一篇 2026年3月18日 上午10:30


相关推荐

  • 淘宝订单编号能查物流吗?一文看懂订单号的隐藏功能!📦

    淘宝订单编号能查物流吗?一文看懂订单号的隐藏功能!📦

    2026年3月15日
    2
  • 从事智能家居行业的企业(Top 45家)

    从事智能家居行业的企业(Top 45家)1、青岛海尔家居集成有限公司(Haier)总部:山东青岛主营:家庭智能终端,可视对讲系统。官网:http://www.haier.com2、霍尼韦尔(Honeywell)总部:美国主营:电子保安系列,视频监控,防盗控制,门禁集成系统。官网:http://www.cn.security.honeywell.com3、广州市河东电子有限公司(HD

    2022年6月22日
    45
  • Mongodb数据库命令端经常使用操作

    Mongodb数据库命令端经常使用操作

    2021年12月4日
    49
  • oracle基本面试题_mongodb面试题

    oracle基本面试题_mongodb面试题1.Oracle跟SQLServer2005的区别?宏观上:1).最大的区别在于平台,oracle可以运行在不同的平台上,sqlserver只能运行在windows平台上,由于windows平台的稳定性和安全性影响了sqlserver的稳定性和安全性2).oracle使用的脚本语言为PL-SQL,而sqlserver使用的脚本为T-SQL微观上:从数据类型,数据库…

    2022年8月29日
    5
  • mac idea 2021激活码【2021免费激活】

    (mac idea 2021激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlS32PGH0SQB-eyJsaWNlbnNlSWQi…

    2022年3月26日
    52
  • mqttnet 详解_mqttnet 简记

    mqttnet 详解_mqttnet 简记1.mqttnet开源库,https://github.com/chkr1011/MQTTnet2.服务器端和客户端服务器端和客户端两个,他们需要保持长连接,主要是通过订阅和发布来进行消息的传递交换。MQTT服务端主要用于与多个客户端保持连接,并处理客户端的发布和订阅等逻辑。一般很少直接从服务端发送消息给客户端(可以使用mqttServer.Publish(appMsg);直接发送消息),多…

    2022年6月25日
    105

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号