/** * 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); }
/** * Obtain a PlatformTransactionManager from the given BeanFactory, matching the given qualifier. * * @param bf the BeanFactory to get the {@code PlatformTransactionManager} bean from * @param qualifier the qualifier for selecting between multiple {@code * PlatformTransactionManager} matches * @return the chosen {@code PlatformTransactionManager} (never {@code null}) * @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found * @deprecated as of Spring 3.1.2 in favor of {@link * BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)} */ @Deprecated public static PlatformTransactionManager getTransactionManager( ConfigurableListableBeanFactory bf, String qualifier) { return BeanFactoryAnnotationUtils.qualifiedBeanOfType( bf, PlatformTransactionManager.class, qualifier); }
/** * Obtain a PlatformTransactionManager from the given BeanFactory, matching the given qualifier. * * @param beanFactory the BeanFactory to get the {@code PlatformTransactionManager} bean from * @param qualifier the qualifier for selecting between multiple {@code * PlatformTransactionManager} matches * @return the chosen {@code PlatformTransactionManager} (never {@code null}) * @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found * @deprecated as of Spring 3.1.2 in favor of {@link * BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)} */ @Deprecated public static PlatformTransactionManager getTransactionManager( BeanFactory beanFactory, String qualifier) { return BeanFactoryAnnotationUtils.qualifiedBeanOfType( beanFactory, PlatformTransactionManager.class, qualifier); }