Mention matching bean names in exception message in case of non-unique EntityManagerFactory lookup

This commit is contained in:
Juergen Hoeller 2012-10-12 16:26:43 +02:00 committed by unknown
parent 538ce4747d
commit d7e2de019f
1 changed files with 4 additions and 2 deletions

View File

@ -60,6 +60,7 @@ import org.springframework.orm.jpa.ExtendedEntityManagerCreator;
import org.springframework.orm.jpa.SharedEntityManagerCreator; import org.springframework.orm.jpa.SharedEntityManagerCreator;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* BeanPostProcessor that processes {@link javax.persistence.PersistenceUnit} * BeanPostProcessor that processes {@link javax.persistence.PersistenceUnit}
@ -521,7 +522,7 @@ public class PersistenceAnnotationBeanPostProcessor
* @throws NoSuchBeanDefinitionException if there is no single EntityManagerFactory in the context * @throws NoSuchBeanDefinitionException if there is no single EntityManagerFactory in the context
*/ */
protected EntityManagerFactory findDefaultEntityManagerFactory(String requestingBeanName) protected EntityManagerFactory findDefaultEntityManagerFactory(String requestingBeanName)
throws NoSuchBeanDefinitionException{ throws NoSuchBeanDefinitionException {
String[] beanNames = String[] beanNames =
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, EntityManagerFactory.class); BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, EntityManagerFactory.class);
@ -535,7 +536,8 @@ public class PersistenceAnnotationBeanPostProcessor
} }
else { else {
throw new NoSuchBeanDefinitionException( throw new NoSuchBeanDefinitionException(
EntityManagerFactory.class, "expected single bean but found " + beanNames.length); EntityManagerFactory.class, "expected single bean but found " + beanNames.length + ": " +
StringUtils.arrayToCommaDelimitedString(beanNames));
} }
} }