diff --git a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java b/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java index 6ee5ecaf7..0c9c4d63d 100644 --- a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java +++ b/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java @@ -142,13 +142,28 @@ public abstract class CdiRepositoryBean implements Bean, PassivationCapabl * Returns an instance of an the given {@link Bean}. * * @param bean the {@link Bean} about to create an instance for. - * @param type the expected type of the component instance created for that {@link Bean}. * @return the actual component instance. + * @see Bean#getTypes() + */ + protected S getDependencyInstance(Bean bean) { + return getDependencyInstance(bean, bean.getBeanClass()); + } + + /** + * Returns an instance of an the given {@link Bean} and allows to be specific about the type that is about to be + * created. + * + * @param bean the {@link Bean} about to create an instance for. + * @param type the expected type of the component instance created for that {@link Bean}. We need to hand this + * parameter explicitly as the {@link Bean} might carry multiple types but the primary one might not be the + * first, i.e. the one returned by {@link Bean#getBeanClass()}. + * @return the actual component instance. + * @see Bean#getTypes() */ @SuppressWarnings("unchecked") - protected S getDependencyInstance(Bean bean) { + protected S getDependencyInstance(Bean bean, Class type) { CreationalContext creationalContext = beanManager.createCreationalContext(bean); - return (S) beanManager.getReference(bean, bean.getBeanClass(), creationalContext); + return (S) beanManager.getReference(bean, type, creationalContext); } /**