1.需要注意springboot的版本和配置文件选择,我就是配置文件和版本有些不对应导致,有些不容看出来的问题,并且不报错。我用的springboot的版本比较低但是可以跑

首先pom:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
    </parent>
    <dependencies>
        <!-- web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- aop -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <!-- 测试 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <!-- 只在test测试里面运行 -->
            <scope>test</scope>
        </dependency>
        <!--jsp-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.19</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>2.0.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.jetty.aggregate</groupId>
                    <artifactId>jetty-all</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.hive</groupId>
                    <artifactId>hive-shims</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

    </dependencies>

其次yml

server:
  port: 8088
  context-path: /xx
spring:
  mvc:
    view:
      prefix: /
      suffix: .jsp
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: org.apache.hive.jdbc.HiveDriver
    url: jdbc:hive2://xxxx
    username:
    password:
  commonConfig: #连接池统一配置,应用到所有的数据源
    initialSize: 1
    minIdle: 1
    maxIdle: 5
    maxActive: 50
    maxWait: 10000
    timeBetweenEvictionRunsMillis: 10000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    maxOpenPreparedStatements: 20
    filters: stat
  http:
    encoding:
      force: true
      charset: utf-8
#mybatis:
#  mapper-locations: com/mapper/*.xml
#  type-aliases-package: com.baizhi.entity
  #jsp热部署
#jsp-servlet:
#  init-parameters:
#    development: true

application

@SpringBootApplication
public class Application {
    public static void main(String[] args){
        SpringApplication.run(Application.class,args);
    }
}

这个文章也写的很好可以看看

controller

@Controller
//@RequestMapping("/app")
public class FileController {
    @Autowired
    FileServiceImpl service;

    @RequestMapping("/query")
    public String queryAll() throws SQLException {
        return "show";
    }

jdbc

@Component
public class HiveJdbc {

    // 自动装配数据源
    @Autowired
    DataSource dataSource;

    //插入数据
    public  Integer insert(String sql) throws SQLException {
        Connection conn = dataSource.getConnection();
        PreparedStatement pstm = conn.prepareStatement(sql);
        int result = pstm.executeUpdate(sql);
        pstm.close();
        conn.close();
        return result;
    }

接下来就是可以自己写一个测试是否可以联系,记得修改自己的配置;

这里得数据库连接是自己简单写的,各位有好的建议可以留言!

也可以参考

https://blog.csdn.net/xiaoxaoyu/article/details/115985145 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐