zoukankan      html  css  js  c++  java
  • springboot 整和 presto

    参考原文:https://blog.csdn.net/Sunhighlight/article/details/89044374

    依赖:

     
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.16.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>


    <dependency>

    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
       <dependency>
          <groupId>com.facebook.presto</groupId>
          <artifactId>presto-jdbc</artifactId>
          <version>0.203</version>
        </dependency>

    配置application.yml文件

     datasource:
        presto:
          name: presto
          type: org.apache.tomcat.jdbc.pool.DataSource
          driver-class-name: com.facebook.presto.jdbc.PrestoDriver
          url: jdbc:presto://192.168.18.129:8881/test/sea
          username: root

    注意:
    (1)本项目其他数据源使用的是阿里巴巴druid数据库连接池,但是该连接池不支持PrestoDB,如果使用会爆出:java.lang.IllegalStateException: dbType not support错误,故我们用org.apache.tomcat.jdbc.pool.DataSource连接池

    3.3创建数据源配置类

    @Configuration
    public class GlobalDataSourceConfiguration {
    
      private static Logger LOG = LoggerFactory.getLogger(GlobalDataSourceConfiguration.class);
    
      @Bean(name = "prestoDataSource")
      @ConfigurationProperties(prefix = "datasource.presto")
      public DataSource prestoDataSource() {
        LOG.info("-------------------- presto init ---------------------");
        return DataSourceBuilder.create().build();
      }
    
      @Bean(name = "prestoTemplate")
      public JdbcTemplate prestoJdbcTemplate(@Qualifier("prestoDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
      }
    
    }

    4.3使用prestoDB直接执行SQL

       @Autowired
       @Qualifier("prestoTemplate")
        private JdbcTemplate prestoTemplate;
    
       List<Map<String, Object>> result =  prestoTemplate.queryForList("sql");
  • 相关阅读:
    怎样把Maven项目共享为传统Web项目
    伸冤人
    Maven依赖
    Maven常用插件参数
    Maven默认周期与插件
    MySQL Connector_J_5.1.34_2014.10
    MyEclipse2015对Javascript自动提示的终极支持
    Struts Convention Plugin 流程 (2.1.6+)
    Maven,预加载资源文件
    Myeclipse2014 自带的报表功能 与 Eclipse BIRT
  • 原文地址:https://www.cnblogs.com/lshan/p/13690316.html
Copyright © 2011-2022 走看看