SpringBoot连接Presto,亲测有效
- 配置依赖
<!-- presto -->
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-jdbc</artifactId>
<version>0.203</version>
</dependency>
- 配置连接参数
#presto
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://127.0.0.1:8889/hive/test
spring.datasource.presto.username=root
- 配置prestojdbc模板
@Slf4j
@Configuration
public class PrestoConfig {
@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);
}
}
- 使用模板
@Autowired
@Qualifier("prestoTemplate")
private JdbcTemplate prestoTemplate;