当前位置: 首页>>代码示例>>Java>>正文


Java TransactionManagementConfigurer类代码示例

本文整理汇总了Java中org.springframework.transaction.annotation.TransactionManagementConfigurer的典型用法代码示例。如果您正苦于以下问题:Java TransactionManagementConfigurer类的具体用法?Java TransactionManagementConfigurer怎么用?Java TransactionManagementConfigurer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TransactionManagementConfigurer类属于org.springframework.transaction.annotation包,在下文中一共展示了TransactionManagementConfigurer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTransactionManager

import org.springframework.transaction.annotation.TransactionManagementConfigurer; //导入依赖的package包/类
/**
 * Get the {@link PlatformTransactionManager transaction manager} to use
 * for the supplied {@link TestContext test context}.
 * @param testContext the test context for which the transaction manager
 * should be retrieved
 * @return the transaction manager to use, or {@code null} if not found
 * @throws BeansException if an error occurs while retrieving the transaction manager
 * @see #getTransactionManager(TestContext, String)
 */
protected final PlatformTransactionManager getTransactionManager(TestContext testContext) {
	BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();
	String tmName = retrieveConfigurationAttributes(testContext).getTransactionManagerName();

	try {
		// look up by type and explicit name from @TransactionConfiguration
		if (StringUtils.hasText(tmName) && !DEFAULT_TRANSACTION_MANAGER_NAME.equals(tmName)) {
			return bf.getBean(tmName, PlatformTransactionManager.class);
		}

		if (bf instanceof ListableBeanFactory) {
			ListableBeanFactory lbf = (ListableBeanFactory) bf;

			// look up single bean by type
			Map<String, PlatformTransactionManager> txMgrs = BeanFactoryUtils.beansOfTypeIncludingAncestors(
				lbf, PlatformTransactionManager.class);
			if (txMgrs.size() == 1) {
				return txMgrs.values().iterator().next();
			}

			// look up single TransactionManagementConfigurer
			Map<String, TransactionManagementConfigurer> configurers = BeanFactoryUtils.beansOfTypeIncludingAncestors(
				lbf, TransactionManagementConfigurer.class);
			if (configurers.size() > 1) {
				throw new IllegalStateException(
					"Only one TransactionManagementConfigurer may exist in the ApplicationContext");
			}
			if (configurers.size() == 1) {
				return configurers.values().iterator().next().annotationDrivenTransactionManager();
			}
		}

		// look up by type and default name from @TransactionConfiguration
		return bf.getBean(DEFAULT_TRANSACTION_MANAGER_NAME, PlatformTransactionManager.class);

	} catch (BeansException ex) {
		if (logger.isWarnEnabled()) {
			logger.warn("Caught exception while retrieving transaction manager for test context " + testContext, ex);
		}
		throw ex;
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:52,代码来源:TransactionalTestExecutionListener.java


注:本文中的org.springframework.transaction.annotation.TransactionManagementConfigurer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。