/**
* Find a single default EntityManagerFactory in the Spring application context.
* @return the default EntityManagerFactory
* @throws NoSuchBeanDefinitionException if there is no single EntityManagerFactory in the context
*/
protected EntityManagerFactory findDefaultEntityManagerFactory(String requestingBeanName)
throws NoSuchBeanDefinitionException {
String[] beanNames =
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, EntityManagerFactory.class);
if (beanNames.length == 1) {
String unitName = beanNames[0];
EntityManagerFactory emf = (EntityManagerFactory) this.beanFactory.getBean(unitName);
if (this.beanFactory instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(unitName, requestingBeanName);
}
return emf;
}
else if (beanNames.length > 1) {
throw new NoUniqueBeanDefinitionException(EntityManagerFactory.class, beanNames);
}
else {
throw new NoSuchBeanDefinitionException(EntityManagerFactory.class);
}
}
PersistenceAnnotationBeanPostProcessor.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:lams
作者:
评论列表
文章目录