PersistenceAnnotationBeanPostProcessor.java 文件源码

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

项目:lams 作者:
/**
 * 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);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号