Introduce BeanFactoryAnnotationUtils
Commit 096693c46f refactored and
deprecated TransactionAspectUtils, moving its #qualifiedBeanOfType
and related methods into BeanFactoryUtils. This created a package cycle
between beans.factory and beans.factory.annotation due to use of the
beans.factory.annotation.Qualifier annotation in these methods.
This commit breaks the package cycle by introducing
beans.factory.annotation.BeanFactoryAnnotationUtils and moving these
@Qualifier-related methods to it. It is intentionally similar in name
and style to the familiar BeanFactoryUtils class for purposes of
discoverability.
There are no backward-compatibilty concerns associated with this change
as the cycle was introduced, caught and now fixed before a release.
Issue: SPR-6847
This commit is contained in:
@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.transaction.NoTransactionException;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -242,7 +243,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||
}
|
||||
String qualifier = txAttr.getQualifier();
|
||||
if (StringUtils.hasLength(qualifier)) {
|
||||
return BeanFactoryUtils.qualifiedBeanOfType(this.beanFactory, PlatformTransactionManager.class, qualifier);
|
||||
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, PlatformTransactionManager.class, qualifier);
|
||||
}
|
||||
else if (this.transactionManagerBeanName != null) {
|
||||
return this.beanFactory.getBean(this.transactionManagerBeanName, PlatformTransactionManager.class);
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.transaction.interceptor;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@@ -40,10 +41,10 @@ public abstract class TransactionAspectUtils {
|
||||
* @return the chosen {@code PlatformTransactionManager} (never {@code null})
|
||||
* @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found
|
||||
* @deprecated as of Spring 3.2 in favor of
|
||||
* {@link BeanFactoryUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
|
||||
* {@link BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
|
||||
*/
|
||||
public static PlatformTransactionManager getTransactionManager(BeanFactory beanFactory, String qualifier) {
|
||||
return BeanFactoryUtils.qualifiedBeanOfType(beanFactory, PlatformTransactionManager.class, qualifier);
|
||||
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, PlatformTransactionManager.class, qualifier);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,10 +54,10 @@ public abstract class TransactionAspectUtils {
|
||||
* @return the chosen {@code PlatformTransactionManager} (never {@code null})
|
||||
* @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found
|
||||
* @deprecated as of Spring 3.2 in favor of
|
||||
* {@link BeanFactoryUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
|
||||
* {@link BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
|
||||
*/
|
||||
public static PlatformTransactionManager getTransactionManager(ConfigurableListableBeanFactory bf, String qualifier) {
|
||||
return BeanFactoryUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
|
||||
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user