Search in sources :

Example 1 with AtomikosDataSourceBean

use of org.springframework.boot.jta.atomikos.AtomikosDataSourceBean in project spring-boot by spring-projects.

the class JtaAutoConfigurationTests method atomikosDataSourcePoolConfiguration.

@Test
public void atomikosDataSourcePoolConfiguration() {
    this.context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "spring.jta.atomikos.datasource.minPoolSize:5", "spring.jta.atomikos.datasource.maxPoolSize:10");
    this.context.register(JtaPropertiesConfiguration.class, AtomikosJtaConfiguration.class, PoolConfiguration.class);
    this.context.refresh();
    AtomikosDataSourceBean dataSource = this.context.getBean(AtomikosDataSourceBean.class);
    assertThat(dataSource.getMinPoolSize()).isEqualTo(5);
    assertThat(dataSource.getMaxPoolSize()).isEqualTo(10);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) Test(org.junit.Test)

Example 2 with AtomikosDataSourceBean

use of org.springframework.boot.jta.atomikos.AtomikosDataSourceBean in project dynamic_dataSource by tianliuzhen.

the class MyBatisConfig1 method oneDataSource.

// 配置第一个数据源
@Primary
@Bean(name = "oneDataSource")
public DataSource oneDataSource() {
    // 这里datasource要使用阿里的支持XA的DruidXADataSource
    DruidXADataSource datasource = new DruidXADataSource();
    BeanUtils.copyProperties(oneDataSourceProperties, datasource);
    AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
    xaDataSource.setXaDataSource(datasource);
    xaDataSource.setUniqueResourceName("oneDataSource");
    return xaDataSource;
}
Also used : AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with AtomikosDataSourceBean

use of org.springframework.boot.jta.atomikos.AtomikosDataSourceBean in project dynamic_dataSource by tianliuzhen.

the class MyBatisConfig2 method twoDataSource.

@Bean(name = "twoDataSource")
public DataSource twoDataSource() {
    DruidXADataSource datasource = new DruidXADataSource();
    BeanUtils.copyProperties(twoDataSourceProperties, datasource);
    AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
    xaDataSource.setXaDataSource(datasource);
    xaDataSource.setUniqueResourceName("twoDataSource");
    return xaDataSource;
}
Also used : AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with AtomikosDataSourceBean

use of org.springframework.boot.jta.atomikos.AtomikosDataSourceBean in project citrus by Yiuman.

the class DynamicDataSourceAutoConfiguration method buildDruidXaDataSource.

/**
 * 根据配置构建XA数据源
 *
 * @param resourceName 资源名,用于定义XA唯一资源
 * @param properties   数据源配置
 * @return XA数据源
 */
public DataSource buildDruidXaDataSource(String resourceName, DataSourceProperties properties) {
    DruidXADataSource druidDataSource = new DruidXADataSource();
    druidDataSource.setUrl(properties.getUrl());
    druidDataSource.setUsername(properties.getUsername());
    druidDataSource.setPassword(properties.getPassword());
    druidDataSource.setDriverClassName(properties.getDriverClassName());
    AtomikosDataSourceBean atomikosDataSourceBean = new AtomikosDataSourceBean();
    atomikosDataSourceBean.setXaDataSource(druidDataSource);
    atomikosDataSourceBean.setUniqueResourceName(String.format("%s$$%s", resourceName, UUID.randomUUID().toString().substring(0, 15)));
    return atomikosDataSourceBean;
}
Also used : AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource)

Aggregations

AtomikosDataSourceBean (org.springframework.boot.jta.atomikos.AtomikosDataSourceBean)4 DruidXADataSource (com.alibaba.druid.pool.xa.DruidXADataSource)3 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)2 Bean (org.springframework.context.annotation.Bean)2 Test (org.junit.Test)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Primary (org.springframework.context.annotation.Primary)1