需求:项目中要使用ClickHouse做数据库。
具体实现:
1,在pom.xml中添加clickhouse依赖
<!-- https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc -->
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2</version>
</dependency>
2, 配置文件中添加clickhouse的配置属性:
spring:
datasource:
clickhouse:
driverClassName: ru.yandex.clickhouse.ClickHouseDirver
url: jdbc:clickhouse:IP:端口号/数据库
user: 用户名
password: 密码
#这部分配置用于kerberos认证
clickhouse:
security:
enabled: true
isMachineUser: false
3,配置Clickhouse连接
@Configuration
public class ClickHouseConfig {
@Value(“{spring.datasource.clickhouse.url}”)
private String clickhouseUrl;
@Value(“{spring.datasource.clickhouse.user}”)
private String clickhouseUser;
@Value(“{spring.datasource.clickhouse.password}”)
private String clickhousePassword;
@Value(“{clickhouse.seurity.enabled}”)
private Boolean isSecurity;
@Value(“{clickhouse.isMachineUser}”)
private Boolean isMachineUser;
@Bean
public DataSource dataSource() {
ClickHouseProperties clickHouseProperties = new ClickHouseProperties();
clickHouseProperties .setSocketTimeout(60000);
//下面三行用于开启kerberos认证
if(isSecurity & isMachineUser) {
clickHouseProperties.setMachineUser(true);
clickHouseProperties.setMachineUserKeytabPath(System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "user.keytab");
}
clickHouseProperties.setSsl(true);
clickHouseProperties.setSslMode("none");
clickHouseProperties.setUser(clickhouseUser);
clickHouseProperties.setPassword(clickhousePassword);
ClickHouseDataSource clickHouseDataSource = new ClickHouseDataSource (clickhouseUrl, clickHouseProperties);
return clickHouseDataSource;
}
}
4,实现具体的Mapper。
其他的操作就跟mysql的操作一致了。
注意:clickhouse跟mysql的SQL语法不一致。
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » SpringBoot集成ClickHouse,含集成kerberos认证
发表评论 取消回复