1.3 spring boot整合presto

首先自己创建spring boot工程,做好基本引用;下面只介绍满足presto的引用

引用pom文件:

<dependencies>

    <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>4.11</version>

        <scope>test</scope>

    </dependency>

    <dependency>

        <groupId>com.facebook.presto</groupId>

        <artifactId>presto-jdbc</artifactId>

        <version>0.203</version>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-test</artifactId>

        <scope>test</scope>

    </dependency>

    <dependency>

        <groupId>org.springframework</groupId>

        <artifactId>spring-jdbc</artifactId>

        <!-- <version>5.1.1.RELEASE</version> -->

    </dependency>

    <!-- 处理No supported DataSource type found错误 -->

    <dependency>

        <groupId>com.zaxxer</groupId>

        <artifactId>HikariCP</artifactId>

        <version>3.2.0</version>

    </dependency>

</dependencies>

application.properties文件:

#

server.port=8000

 

spring.datasource.presto.name=presto

spring.datasource.presto.type=org.apache.tomcat.jdbc.pool.DataSource

spring.datasource.presto.driver-class-name=com.facebook.presto.jdbc.PrestoDriver

spring.datasource.presto.jdbc-url=jdbc:presto://192.168.227.3:8001/system/runtime //url改成jdbc-url,不然可能会报jdbcUrl is required with driverClassName

spring.datasource.presto.username=root

数据源配置类:

import javax.sql.DataSource;

 

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.boot.jdbc.DataSourceBuilder;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.jdbc.core.JdbcTemplate;

/**

* <p>创建数据源配置类</p>

* 2019年7月4日上午8:52:44

* @author lvjie

*/

@Configuration

public class GlobalDataSourceConfiguration {

    private static Logger LOG = LoggerFactory.getLogger(GlobalDataSourceConfiguration.class);

 

    @Bean(name = "prestoDataSource")

    @ConfigurationProperties(prefix = "spring.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);

    }

}

访问使用类:

import java.util.List;

import java.util.Map;

 

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.jdbc.core.JdbcTemplate;

import org.springframework.stereotype.Service;

 

import com.hww.boot.service.ITestService;

@Service

public class TestServiceImpl implements ITestService{

    @Autowired

    @Qualifier("prestoTemplate")

    private JdbcTemplate prestoTemplate;

 

    @Override

    public List<Map<String, Object>> findList() {

    // TODO Auto-generated method stub

        return prestoTemplate.queryForList("SELECT a.id,a.name,b.id,b.name FROM postgresql.public.fd_area a,mongodb.test.user b where a.id = b.id");

    }

}

 

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值