首页 > 数据库 >springboot jpa hibernate mysql clickhouse 多数据源

springboot jpa hibernate mysql clickhouse 多数据源

时间:2023-03-03 10:35:28浏览次数:40  
标签:hibernate springboot 数据源 builder clickhouseEntityManagerFactory Bean dataSource 

ClickhouseConfig.java
@Configuration
@EntityScan(basePackages = "test.entity.clickhouse")
@EnableJpaRepositories(
        basePackages = "test.repository.clickhouse",
        entityManagerFactoryRef = "clickhouseEntityManagerFactory",
        transactionManagerRef = "clickhouseTransactionManager",
        repositoryBaseClass = BaseRepositoryImpl.class)
//        enableDefaultTransactions = false)
@EnableTransactionManagement
public class ClickhouseConfig {
    @Autowired
    @Qualifier("clickhouseDataSource")
    private DataSource dataSource;

    @Autowired
    @Qualifier("vendorClickhouseProperties")
    private Map<String, Object> vendorProperties;

    @Bean(name = "clickhouseEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean clickhouseEntityManagerFactory(EntityManagerFactoryBuilder builder) {
        return builder
                .dataSource(dataSource)
                .properties(vendorProperties)
                .packages("com.zcunsoft.tracking.report.entity.clickhouse")
                .persistenceUnit("clickhousePersistenceUnit")
                .build();

    }

    @Bean(name = "clickhouseEntityManager")
    public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
        return clickhouseEntityManagerFactory(builder).getObject().createEntityManager();
    }

    @Bean(name = "clickhouseTransactionManager")
    PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
        return new JpaTransactionManager(clickhouseEntityManagerFactory(builder).getObject());
    }


    @Bean(name = "clickHouseJdbcTemplate")
    public NamedParameterJdbcTemplate clickHouseJdbcTemplate(
            @Qualifier("clickhouseDataSource") DataSource dataSource) {
        return new NamedParameterJdbcTemplate(dataSource);
    }
}

  

标签:hibernate,springboot,数据源,builder,clickhouseEntityManagerFactory,Bean,dataSource,
From: https://www.cnblogs.com/merseyalma/p/17174668.html

相关文章

  • seata数据源代理
    seata数据源代理流程1-SeataDataSourceAutoConfiguration创建SeataAutoDataSourceProxyCreator对象,默认seata模式为AT2-SeataAutoDataSourceProxyCreator设置advisor......
  • 视频上传及压缩SpringBoot
    在SpringBoot项目中实现视频的上传和下载,地址都是存放至阿里云的,但是由于视频数量越来越多占用的内存也越来越大,导致服务器内存不足,公司为了减少服务器开支,要求我们研......
  • Springboot打包部署的步骤
    1.配置pom.xml引入插件<groupId>com.bostech</groupId><artifactId>dcs</artifactId><version>0.0.1-SNAPSHOT</version><!--注意把packaging标签改为jar......
  • springboot gradle 集成流程引擎activiti
    plugins{id'org.springframework.boot'version'2.1.4.RELEASE'id'io.spring.dependency-management'version'1.0.13.RELEASE'id'java'}group=......
  • springboot application.yml 配置说明
    1.springbootapplication.yml配置说明server:port:8080spring:datasource:username:rootpassword:123456driver-class-name:com.mysql.cj.......
  • unixODBC 不使用GUI配置数据源
     {PurposeAlotofpeopleareusingunixODBCbutforanumberofreasonsarenotbuildingtheGUIconfigurationandtestingtools(ODBCConfigandDataManage......
  • SpringBoot内部方法之间跳转
    从controller的一个方法跳转到另一个方法中可以通过重定向实现,重定向具体语法:redirect:要访问的网址具体请看下面示例:@Controller@RequestMapping("/user")publicclass......
  • SpringBoot整合MapStruct
    第一步:添加依赖<dependency><groupId>org.mapstruct</groupId><artifactId>mapstruct</artifactId><version>1.5.3.Final</version></dependency>第二步......
  • SpringBoot2.6 集成Druid 启动项目 运行SQL文件 自动生成数据库表及数据
    SpringBoot项目启动运行SQL文件自动生成数据库表及数据。第一步:创建SpringBoot项目,添加依赖<dependency><groupId>mysql</groupId><artifactId>mysql-connect......
  • Springboot Condition 实用讲解,只看一遍包学会
    前言 该篇文章,还是一贯的风格,源码+示例+自言自语的分析,目的只有一个:就是想让大家都会玩 Condition、Conditional。   正文先看看Condition是被放在包spr......