From 90683ed68a590a0a1ca11568b65ede0c8bacd3e1 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 11 Oct 2016 15:53:07 +0200 Subject: [PATCH] =?UTF-8?q?DATACMNS-867=20-=20Re-introduced=20CdiRepositor?= =?UTF-8?q?yBean.getDependencyInstance(=E2=80=A6)=20with=20explicit=20type?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/cdi/CdiRepositoryBean.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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); } /**