类org.springframework.boot.jdbc.XADataSourceWrapper源码实例Demo

下面列出了怎么用org.springframework.boot.jdbc.XADataSourceWrapper的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
public void allDefaultBeansShouldBeLoaded() {
    this.context = new AnnotationConfigApplicationContext(NarayanaConfiguration.class);
    this.context.getBean(NarayanaBeanFactoryPostProcessor.class);
    this.context.getBean(XADataSourceWrapper.class);
    this.context.getBean(XAConnectionFactoryWrapper.class);
    this.context.getBean(NarayanaPropertiesInitializer.class);
    this.context.getBean(UserTransaction.class);
    this.context.getBean(TransactionManager.class);
    this.context.getBean(JtaTransactionManager.class);
    this.context.getBean(RecoveryManagerService.class);
    this.context.getBean(XARecoveryModule.class);
}
 
@Test
public void genericXaDataSourceWrapperShouldBeLoaded() {
    Properties properties = new Properties();
    properties.put("narayana.dbcp.enabled", "false");
    PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);

    this.context = new AnnotationConfigApplicationContext();
    this.context.register(NarayanaConfiguration.class);
    this.context.getEnvironment().getPropertySources().addFirst(propertySource);
    this.context.refresh();

    XADataSourceWrapper xaDataSourceWrapper = this.context.getBean(XADataSourceWrapper.class);
    assertThat(xaDataSourceWrapper).isInstanceOf(GenericXADataSourceWrapper.class);
}
 
@Test
public void pooledXaDataSourceWrapperShouldBeLoaded() {
    Properties properties = new Properties();
    properties.put("narayana.dbcp.enabled", "true");
    PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);

    this.context = new AnnotationConfigApplicationContext();
    this.context.register(NarayanaConfiguration.class);
    this.context.getEnvironment().getPropertySources().addFirst(propertySource);
    this.context.refresh();

    XADataSourceWrapper xaDataSourceWrapper = this.context.getBean(XADataSourceWrapper.class);
    assertThat(xaDataSourceWrapper).isInstanceOf(PooledXADataSourceWrapper.class);
}
 
@Bean
@ConditionalOnMissingBean(XADataSourceWrapper.class)
public XADataSourceWrapper xaDataSourceWrapper(NarayanaProperties narayanaProperties,
        XARecoveryModule xaRecoveryModule) {
    return new GenericXADataSourceWrapper(narayanaProperties, xaRecoveryModule);
}
 
@Bean
@ConditionalOnMissingBean(XADataSourceWrapper.class)
public XADataSourceWrapper xaDataSourceWrapper(NarayanaProperties narayanaProperties,
        XARecoveryModule xaRecoveryModule, TransactionManager transactionManager) {
    return new PooledXADataSourceWrapper(narayanaProperties, xaRecoveryModule, transactionManager);
}
 
 类所在包
 同包方法