2424import org .springframework .beans .BeansException ;
2525import org .springframework .beans .factory .config .BeanDefinition ;
2626import org .springframework .beans .factory .support .AbstractBeanDefinition ;
27- import org .springframework .beans .factory .support .RootBeanDefinition ;
2827import org .springframework .core .ParameterizedTypeReference ;
2928import org .springframework .core .ResolvableType ;
3029import org .springframework .core .env .Environment ;
@@ -55,43 +54,92 @@ public interface BeanRegistry {
5554 void registerAlias (String name , String alias );
5655
5756 /**
58- * Register a bean from the given bean class, which will be instantiated using the
57+ * Register a bean from the given class, which will be instantiated using the
5958 * related {@link BeanUtils#getResolvableConstructor resolvable constructor} if any.
59+ * <p>For registering a bean with a generic type, consider
60+ * {@link #registerBean(ParameterizedTypeReference)}.
6061 * @param beanClass the class of the bean
6162 * @return the generated bean name
63+ * @see #registerBean(Class)
6264 */
6365 <T > String registerBean (Class <T > beanClass );
6466
6567 /**
66- * Register a bean from the given bean class, customizing it with the customizer
68+ * Register a bean from the given generics-containing type, which will be
69+ * instantiated using the related
70+ * {@link BeanUtils#getResolvableConstructor resolvable constructor} if any.
71+ * @param beanType the generics-containing type of the bean
72+ * @return the generated bean name
73+ */
74+ <T > String registerBean (ParameterizedTypeReference <T > beanType );
75+
76+ /**
77+ * Register a bean from the given class, customizing it with the customizer
6778 * callback. The bean will be instantiated using the supplier that can be configured
6879 * in the customizer callback, or will be tentatively instantiated with its
6980 * {@link BeanUtils#getResolvableConstructor resolvable constructor} otherwise.
81+ * <p>For registering a bean with a generic type, consider
82+ * {@link #registerBean(ParameterizedTypeReference, Consumer)}.
7083 * @param beanClass the class of the bean
71- * @param customizer callback to customize other bean properties than the name
84+ * @param customizer the callback to customize other bean properties than the name
7285 * @return the generated bean name
7386 */
7487 <T > String registerBean (Class <T > beanClass , Consumer <Spec <T >> customizer );
7588
7689 /**
77- * Register a bean from the given bean class, which will be instantiated using the
90+ * Register a bean from the given generics-containing type, customizing it
91+ * with the customizer callback. The bean will be instantiated using the supplier
92+ * that can be configured in the customizer callback, or will be tentatively instantiated
93+ * with its {@link BeanUtils#getResolvableConstructor resolvable constructor} otherwise.
94+ * @param beanType the generics-containing type of the bean
95+ * @param customizer the callback to customize other bean properties than the name
96+ * @return the generated bean name
97+ */
98+ <T > String registerBean (ParameterizedTypeReference <T > beanType , Consumer <Spec <T >> customizer );
99+
100+ /**
101+ * Register a bean from the given class, which will be instantiated using the
78102 * related {@link BeanUtils#getResolvableConstructor resolvable constructor} if any.
103+ * <p>For registering a bean with a generic type, consider
104+ * {@link #registerBean(String, ParameterizedTypeReference)}.
79105 * @param name the name of the bean
80106 * @param beanClass the class of the bean
81107 */
82108 <T > void registerBean (String name , Class <T > beanClass );
83109
84110 /**
85- * Register a bean from the given bean class, customizing it with the customizer
111+ * Register a bean from the given generics-containing type, which
112+ * will be instantiated using the related
113+ * {@link BeanUtils#getResolvableConstructor resolvable constructor} if any.
114+ * @param name the name of the bean
115+ * @param beanType the generics-containing type of the bean
116+ */
117+ <T > void registerBean (String name , ParameterizedTypeReference <T > beanType );
118+
119+ /**
120+ * Register a bean from the given class, customizing it with the customizer
86121 * callback. The bean will be instantiated using the supplier that can be configured
87122 * in the customizer callback, or will be tentatively instantiated with its
88123 * {@link BeanUtils#getResolvableConstructor resolvable constructor} otherwise.
124+ * <p>For registering a bean with a generic type, consider
125+ * {@link #registerBean(String, ParameterizedTypeReference, Consumer)}.
89126 * @param name the name of the bean
90127 * @param beanClass the class of the bean
91- * @param customizer callback to customize other bean properties than the name
128+ * @param customizer the callback to customize other bean properties than the name
92129 */
93130 <T > void registerBean (String name , Class <T > beanClass , Consumer <Spec <T >> customizer );
94131
132+ /**
133+ * Register a bean from the given generics-containing type, customizing it
134+ * with the customizer callback. The bean will be instantiated using the supplier
135+ * that can be configured in the customizer callback, or will be tentatively instantiated
136+ * with its {@link BeanUtils#getResolvableConstructor resolvable constructor} otherwise.
137+ * @param name the name of the bean
138+ * @param beanType the generics-containing type of the bean
139+ * @param customizer the callback to customize other bean properties than the name
140+ */
141+ <T > void registerBean (String name , ParameterizedTypeReference <T > beanType , Consumer <Spec <T >> customizer );
142+
95143
96144 /**
97145 * Specification for customizing a bean.
@@ -164,20 +212,6 @@ interface Spec<T> {
164212 * @see AbstractBeanDefinition#setInstanceSupplier(Supplier)
165213 */
166214 Spec <T > supplier (Function <SupplierContext , T > supplier );
167-
168- /**
169- * Set a generics-containing target type of this bean.
170- * @see #targetType(ResolvableType)
171- * @see RootBeanDefinition#setTargetType(ResolvableType)
172- */
173- Spec <T > targetType (ParameterizedTypeReference <? extends T > type );
174-
175- /**
176- * Set a generics-containing target type of this bean.
177- * @see #targetType(ParameterizedTypeReference)
178- * @see RootBeanDefinition#setTargetType(ResolvableType)
179- */
180- Spec <T > targetType (ResolvableType type );
181215 }
182216
183217
@@ -188,32 +222,40 @@ interface Spec<T> {
188222 interface SupplierContext {
189223
190224 /**
191- * Return the bean instance that uniquely matches the given object type, if any.
192- * @param requiredType type the bean must match; can be an interface or superclass
193- * @return an instance of the single bean matching the required type
225+ * Return the bean instance that uniquely matches the given type, if any.
226+ * @param beanClass the type the bean must match; can be an interface or superclass
227+ * @return an instance of the single bean matching the bean type
228+ * @see BeanFactory#getBean(String)
229+ */
230+ <T > T bean (Class <T > beanClass ) throws BeansException ;
231+
232+ /**
233+ * Return the bean instance that uniquely matches the given generics-containing type, if any.
234+ * @param beanType the generics-containing type the bean must match; can be an interface or superclass
235+ * @return an instance of the single bean matching the bean type
194236 * @see BeanFactory#getBean(String)
195237 */
196- <T > T bean (Class <T > requiredType ) throws BeansException ;
238+ <T > T bean (ParameterizedTypeReference <T > beanType ) throws BeansException ;
197239
198240 /**
199241 * Return an instance, which may be shared or independent, of the
200242 * specified bean.
201243 * @param name the name of the bean to retrieve
202- * @param requiredType type the bean must match; can be an interface or superclass
244+ * @param beanClass the type the bean must match; can be an interface or superclass
203245 * @return an instance of the bean.
204246 * @see BeanFactory#getBean(String, Class)
205247 */
206- <T > T bean (String name , Class <T > requiredType ) throws BeansException ;
248+ <T > T bean (String name , Class <T > beanClass ) throws BeansException ;
207249
208250 /**
209251 * Return a provider for the specified bean, allowing for lazy on-demand retrieval
210252 * of instances, including availability and uniqueness options.
211- * <p>For matching a generic type, consider {@link #beanProvider(ResolvableType )}.
212- * @param requiredType type the bean must match; can be an interface or superclass
253+ * <p>For matching a generic type, consider {@link #beanProvider(ParameterizedTypeReference )}.
254+ * @param beanClass the type the bean must match; can be an interface or superclass
213255 * @return a corresponding provider handle
214256 * @see BeanFactory#getBeanProvider(Class)
215257 */
216- <T > ObjectProvider <T > beanProvider (Class <T > requiredType );
258+ <T > ObjectProvider <T > beanProvider (Class <T > beanClass );
217259
218260 /**
219261 * Return a provider for the specified bean, allowing for lazy on-demand retrieval
@@ -229,11 +271,11 @@ interface SupplierContext {
229271 * Java compiler warning), consider calling {@link #beanProvider(Class)} with the
230272 * raw type as a second step if no full generic match is
231273 * {@link ObjectProvider#getIfAvailable() available} with this variant.
232- * @param requiredType type the bean must match; can be a generic type declaration
274+ * @param beanType the generics-containing type the bean must match; can be an interface or superclass
233275 * @return a corresponding provider handle
234276 * @see BeanFactory#getBeanProvider(ResolvableType)
235277 */
236- <T > ObjectProvider <T > beanProvider (ResolvableType requiredType );
278+ <T > ObjectProvider <T > beanProvider (ParameterizedTypeReference < T > beanType );
237279 }
238280
239281}
0 commit comments