TransactionalTestExecutionListener.java 文件源码

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

项目:class-guard 作者:
/**
 * Get the {@link PlatformTransactionManager transaction manager} to use
 * for the supplied {@link 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 final 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("Caught exception while retrieving transaction manager for test context " + testContext
                        + " and qualifier [" + qualifier + "]", ex);
            }
            throw ex;
        }
    }

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


问题


面经


文章

微信
公众号

扫码关注公众号