|
1 | 1 | /* |
2 | | - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -76,10 +76,12 @@ public abstract class EntityManagerFactoryUtils { |
76 | 76 | * Find an EntityManagerFactory with the given name in the given |
77 | 77 | * Spring application context (represented as ListableBeanFactory). |
78 | 78 | * <p>The specified unit name will be matched against the configured |
79 | | - * peristence unit, provided that a discovered EntityManagerFactory |
| 79 | + * persistence unit, provided that a discovered EntityManagerFactory |
80 | 80 | * implements the {@link EntityManagerFactoryInfo} interface. If not, |
81 | 81 | * the persistence unit name will be matched against the Spring bean name, |
82 | 82 | * assuming that the EntityManagerFactory bean names follow that convention. |
| 83 | + * <p>If no unit name has been given, this method will search for a default |
| 84 | + * EntityManagerFactory through {@link ListableBeanFactory#getBean(Class)}. |
83 | 85 | * @param beanFactory the ListableBeanFactory to search |
84 | 86 | * @param unitName the name of the persistence unit (may be {@code null} or empty, |
85 | 87 | * in which case a single bean of type EntityManagerFactory will be searched for) |
@@ -108,7 +110,8 @@ public static EntityManagerFactory findEntityManagerFactory( |
108 | 110 | return beanFactory.getBean(unitName, EntityManagerFactory.class); |
109 | 111 | } |
110 | 112 | else { |
111 | | - return BeanFactoryUtils.beanOfType(beanFactory, EntityManagerFactory.class); |
| 113 | + // Find unique EntityManagerFactory bean in the context, falling back to parent contexts. |
| 114 | + return beanFactory.getBean(EntityManagerFactory.class); |
112 | 115 | } |
113 | 116 | } |
114 | 117 |
|
|
0 commit comments