
# 调测Hive SpringBoot样例程序
该章节内容适用于MRS 3.3.0及之后版本。
#### SpringBoot样例工程的命令行形式运行
1. 在IDEA界面左下方单击"Terminal"进入终端，执行命令**mvn clean package** 进行编译。
   
   ![](https://support.huaweicloud.com/devg-lts-mrs/zh-cn_image_0000001732211429.png "点击放大")
   当输出"BUILD SUCCESS"，表示编译成功，如下图所示。编译成功后将会在样例工程的target下生成含有"-with-dependencies"字段的Jar包。
   ![](https://support.huaweicloud.com/devg-lts-mrs/zh-cn_image_0000001684132598.png "点击放大")
   
   
2. 在Windows或Linux上创建一个目录作为运行目录，如"D:\\hive-rest-client-example"（Windows环境）或"/opt/hive-rest-client-example"（Linux环境），将[1]中生成的"target"目录下包名中含有"-with-dependencies"字段的Jar包放进该路径下，并在该目录下创建子目录"src/main/resources"。将hive-rest-client-example工程resources目录下的所有文件复制到"resources"下。
3. 执行以下命令启动SpringBoot服务： 
   - 在Windows环境下执行： **cd /d d:\\hive-rest-client-example**
     **java -jar hive-rest-client-example-** *8.1.0.1* **-** *3.7.0* **-SNAPSHOT-jar-with-dependencies.jar**
     
   
   - 在Linux环境下执行： **chmod +x /opt/hive-rest-client-example -R**
     **cd /opt/hive-rest-client-example**
     **java -jar hive-rest-client-example-** *8.1.0.1* **-** *3.7.0* **-SNAPSHOT-jar-with-dependencies.jar**
     
   
   
   ![](https://support.huaweicloud.com/devg-lts-mrs/public_sys-resources/note_3.0-zh-cn.png)
   以上Jar包名称仅供参考，具体名称以实际生成为主。
   
   
4. 调用Hive的SpringBoot样例接口触发样例代码运行： 
   - Windows环境运行方式： 打开浏览器，输入：http://localhost:8080/hive/example/executesql。
     
   
   - Linux环境下执行运行方式： 在[2]中存放Jar的节点上执行**curl http://localhost:8080/hive/example/executesql**命令。
     
   
   
   ![](https://support.huaweicloud.com/devg-lts-mrs/public_sys-resources/note_3.0-zh-cn.png)
   运行样例代码时日志中可能会打印以下日志信息，虽然日志级别显示ERROR，但是不影响执行结果：
   ```
   ERROR 51320 --- [c-8-EventThread] o.a.c.framework.imps.EnsembleTracker     : Invalid config event received: {version=100000000, server.48=ZooKeeper节点IP地址:ZooKeeper端口号:ZooKeeper端口号:participant...}
   ```
   
   
5. 查看样例代码中的HQL所查询出的结果。 
   - Windows环境运行成功结果会有如下信息：
     ```
     =========================== Hive Example Start ===========================
     Start create table.
     Table created successfully.
     Start to insert data into the table.
     Inserting data to the table succeeded.
     Start to query table data.
     Query result :
     employees_infoa.id    employees_infoa.age    employees_infoa.name
     1    31    SJK
     2    25    HS
     3    28    HT
     Querying table data succeeded.
     Start to delete the table.
     Table deleted successfully.
     =========================== Hive Example End ===========================
     ```
     
   
   - Linux环境运行成功结果会有如下信息：
     ```
     =========================== Hive Example Start ===========================
     Start create table.
     Table created successfully.
     Start to insert data into the table.
     Inserting data to the table succeeded.
     Start to query table data.
     Query result :
     employees_infoa.id    employees_infoa.age    employees_infoa.name
     1    31    SJK
     2    25    HS
     3    28    HT
     Querying table data succeeded.
     Start to delete the table.
     Table deleted successfully.
     =========================== Hive Example End ===========================
     ```
     
   
   
   
   
 
