TransactionalTestExecutionListener.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:spring4-understanding 作者:
/**
 * Get the {@linkplain PlatformTransactionManager transaction manager} to use
 * for the supplied {@linkplain TestContext test context} and {@code qualifier}.
 * <p>Delegates to {@link #getTransactionManager(TestContext)} if the
 * supplied {@code qualifier} is {@code null} or empty.
 * @param testContext the test context for which the transaction manager
 * should be retrieved
 * @param qualifier the qualifier for selecting between multiple bean matches;
 * may be {@code null} or empty
 * @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)
 */
protected PlatformTransactionManager getTransactionManager(TestContext testContext, String qualifier) {
    // look up by type and qualifier from @Transactional
    if (StringUtils.hasText(qualifier)) {
        try {
            // Use autowire-capable factory in order to support extended qualifier
            // matching (only exposed on the internal BeanFactory, not on the
            // ApplicationContext).
            BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();

            return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
        }
        catch (RuntimeException ex) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                    String.format(
                        "Caught exception while retrieving transaction manager with qualifier '%s' for test context %s",
                        qualifier, testContext), ex);
            }
            throw ex;
        }
    }

    // else
    return getTransactionManager(testContext);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号