Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

spring boot + bytehouse 配置示例 #18

@zhugw

Description

@zhugw

我这边用的是MySQL 但是数据量大了 查询变慢了 想要改用bytehouse 现有的技术栈是 Spring boot + mybatis
官方也没有一个标准的示例 只好参考晚上clickhouse的例子 写了一个也不知道是否符合最佳实践

application-dev.yml

spring:
  datasource:
    bytehouse:
      url: jdbc:bytehouse://bytehouse-cn-beijing.volces.com:19000?secure=true&user=bytehouse&password=xxx

com.example.bytehousedemo.config.ByteHouseParamConfig

@Component
@ConfigurationProperties(prefix = "spring.datasource.bytehouse")
@Data
public class ByteHouseParamConfig {
    private String url ;
}

com.example.bytehousedemo.config.ByteHouseConfig

@Configuration
@MapperScan(basePackages = {
        "com.example.bytehousedemo.mapper"
})
public class ByteHouseConfig {
    @Resource
    private ByteHouseParamConfig byteHouseParamConfig;
    @Bean(name = "bytehouseDataSource")
    public DataSource dataSource() {
        DataSource dataSource = new ByteHouseDataSource(byteHouseParamConfig.getUrl());
        return dataSource;
    }


    @Bean
    public SqlSessionFactory byteHouseSqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
        factory.setDataSource(dataSource());
        // 实体 model的 路径 比如 com.order.model
        factory.setTypeAliasesPackage("com.example.bytehousedemo.model");
        //添加XML目录
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
        //开启驼峰命名转换
        factory.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
        return factory.getObject();
    }


}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions