SpringBoot链接trino中间件

工具连接trino

工具:DBeaver

旧版本的DBeaver能链接presto但不能链接trino,更新到最新版后(安装了版本21.1.2.202107041908)后,添加了trino链接源,下载驱动,输入信息链接成功;

SpringBoot链接trino

网络上搜索trino资料很少,更搜索不到SpringBoot如何链接trino,后折腾了一番,终于解决问题,现做个记录;

查询官网,找到依赖包

 通过DBeaver链接找到驱动类

SpringBoot配置:

pom.xml

<dependency>
   <groupId>io.trino</groupId>
   <artifactId>trino-jdbc</artifactId>
   <version>359</version>
</dependency>

 application.properties

spring.datasource.presto.name=presto
spring.datasource.presto.driver-class-name=io.trino.jdbc.TrinoDriver
spring.datasource.presto.jdbc-url=jdbc:trino://127.0.0.1:8090/demo
spring.datasource.presto.username=demo

 数据源配置:

@Bean(name = "prestoDataSource")
@ConfigurationProperties(prefix = "spring.datasource.presto")
public DataSource getPrestoDataSource() {
   return DataSourceBuilder.create().build();
}

@Conditional(UseDsPrstoCondition.class)
@Bean(name = "prestoJdbcTemplate")
public JdbcTemplate prestoJdbcTemplate(@Qualifier("prestoDataSource") DataSource dataSource) {
   return new JdbcTemplate(dataSource);
}

使用:

public static JdbcTemplate getJdbcTemplate(TemplateName name) {
   return applicationContext.getBean("prestoDataSource", JdbcTemplate.class);
}
getJdbcTemplate().queryForList(sql);

版权声明:本文为weixin_42260124原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。