21
21
import org .springframework .beans .factory .config .AutowiredPropertyMarker ;
22
22
import org .springframework .beans .factory .config .BeanDefinitionCustomizer ;
23
23
import org .springframework .beans .factory .config .RuntimeBeanReference ;
24
+ import org .springframework .core .ResolvableType ;
24
25
import org .springframework .lang .Nullable ;
25
26
import org .springframework .util .ObjectUtils ;
26
27
@@ -102,7 +103,7 @@ public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName, @Nu
102
103
* @param beanClass the {@code Class} of the bean that the definition is being created for
103
104
*/
104
105
public static BeanDefinitionBuilder rootBeanDefinition (Class <?> beanClass ) {
105
- return rootBeanDefinition (beanClass , null );
106
+ return rootBeanDefinition (beanClass , ( String ) null );
106
107
}
107
108
108
109
/**
@@ -117,6 +118,30 @@ public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass, @Null
117
118
return builder ;
118
119
}
119
120
121
+ /**
122
+ * Create a new {@code BeanDefinitionBuilder} used to construct a {@link RootBeanDefinition}.
123
+ * @param beanType the {@link ResolvableType type} of the bean that the definition is being created for
124
+ * @param instanceSupplier a callback for creating an instance of the bean
125
+ * @since 5.3.9
126
+ */
127
+ public static <T > BeanDefinitionBuilder rootBeanDefinition (ResolvableType beanType , Supplier <T > instanceSupplier ) {
128
+ RootBeanDefinition beanDefinition = new RootBeanDefinition ();
129
+ beanDefinition .setTargetType (beanType );
130
+ beanDefinition .setInstanceSupplier (instanceSupplier );
131
+ return new BeanDefinitionBuilder (beanDefinition );
132
+ }
133
+
134
+ /**
135
+ * Create a new {@code BeanDefinitionBuilder} used to construct a {@link RootBeanDefinition}.
136
+ * @param beanClass the {@code Class} of the bean that the definition is being created for
137
+ * @param instanceSupplier a callback for creating an instance of the bean
138
+ * @since 5.3.9
139
+ * @see #rootBeanDefinition(ResolvableType, Supplier)
140
+ */
141
+ public static <T > BeanDefinitionBuilder rootBeanDefinition (Class <T > beanClass , Supplier <T > instanceSupplier ) {
142
+ return rootBeanDefinition (ResolvableType .forClass (beanClass ), instanceSupplier );
143
+ }
144
+
120
145
/**
121
146
* Create a new {@code BeanDefinitionBuilder} used to construct a {@link ChildBeanDefinition}.
122
147
* @param parentName the name of the parent bean
0 commit comments