16
16
17
17
package org.springframework.context.support
18
18
19
+ import org.springframework.beans.factory.config.BeanDefinition
19
20
import org.springframework.beans.factory.config.BeanDefinitionCustomizer
20
21
import org.springframework.beans.factory.support.AbstractBeanDefinition
21
22
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils
@@ -97,11 +98,13 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
97
98
* Scope enum constants.
98
99
*/
99
100
enum class Scope {
101
+
100
102
/* *
101
103
* Scope constant for the standard singleton scope
102
104
* @see org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON
103
105
*/
104
106
SINGLETON ,
107
+
105
108
/* *
106
109
* Scope constant for the standard singleton scope
107
110
* @see org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE
@@ -119,11 +122,13 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
119
122
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_NO
120
123
*/
121
124
NO ,
125
+
122
126
/* *
123
127
* Autowire constant that indicates autowiring bean properties by name
124
128
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_BY_NAME
125
129
*/
126
130
BY_NAME ,
131
+
127
132
/* *
128
133
* Autowire constant that indicates autowiring bean properties by type
129
134
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE
@@ -138,6 +143,41 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
138
143
139
144
}
140
145
146
+
147
+ /* *
148
+ * Role enum constants.
149
+ */
150
+ enum class Role {
151
+
152
+ /* *
153
+ * Role hint indicating that a [BeanDefinition] is a major part
154
+ * of the application. Typically corresponds to a user-defined bean.
155
+ * @see org.springframework.beans.factory.config.BeanDefinition.ROLE_APPLICATION
156
+ */
157
+ APPLICATION ,
158
+
159
+ /* *
160
+ * Role hint indicating that a [BeanDefinition] is a supporting
161
+ * part of some larger configuration, typically an outer
162
+ * [org.springframework.beans.factory.parsing.ComponentDefinition].
163
+ * [SUPPORT] beans are considered important enough to be aware of
164
+ * when looking more closely at a particular
165
+ * [org.springframework.beans.factory.parsing.ComponentDefinition],
166
+ * but not when looking at the overall configuration of an application.
167
+ * @see org.springframework.beans.factory.config.BeanDefinition.ROLE_SUPPORT
168
+ */
169
+ SUPPORT ,
170
+
171
+ /* *
172
+ * Role hint indicating that a [BeanDefinition] is providing an
173
+ * entirely background role and has no relevance to the end-user. This hint is
174
+ * used when registering beans that are completely part of the internal workings
175
+ * of a [org.springframework.beans.factory.parsing.ComponentDefinition].
176
+ * @see org.springframework.beans.factory.config.BeanDefinition.ROLE_INFRASTRUCTURE
177
+ */
178
+ INFRASTRUCTURE
179
+ }
180
+
141
181
/* *
142
182
* Declare a bean definition from the given bean class which can be inferred when possible.
143
183
*
@@ -148,6 +188,10 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
148
188
* @param autowireMode Set the autowire mode, `Autowire.CONSTRUCTOR` by default
149
189
* @param isAutowireCandidate Set whether this bean is a candidate for getting
150
190
* autowired into some other bean.
191
+ * @param initMethodName Set the name of the initializer method
192
+ * @param destroyMethodName Set the name of the destroy method
193
+ * @param description Set a human-readable description of this bean definition
194
+ * @param role Set the role hint for this bean definition
151
195
* @see GenericApplicationContext.registerBean
152
196
* @see org.springframework.beans.factory.config.BeanDefinition
153
197
*/
@@ -156,13 +200,21 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
156
200
isLazyInit : Boolean? = null,
157
201
isPrimary : Boolean? = null,
158
202
autowireMode : Autowire = Autowire .CONSTRUCTOR ,
159
- isAutowireCandidate : Boolean? = null) {
203
+ isAutowireCandidate : Boolean? = null,
204
+ initMethodName : String? = null,
205
+ destroyMethodName : String? = null,
206
+ description : String? = null,
207
+ role : Role = Role .APPLICATION ) {
160
208
161
209
val customizer = BeanDefinitionCustomizer { bd ->
162
210
scope?.let { bd.scope = scope.name.toLowerCase() }
163
211
isLazyInit?.let { bd.isLazyInit = isLazyInit }
164
212
isPrimary?.let { bd.isPrimary = isPrimary }
165
213
isAutowireCandidate?.let { bd.isAutowireCandidate = isAutowireCandidate }
214
+ initMethodName?.let { bd.initMethodName = initMethodName }
215
+ destroyMethodName?.let { bd.destroyMethodName = destroyMethodName }
216
+ description?.let { bd.description = description }
217
+ bd.role = role.ordinal
166
218
if (bd is AbstractBeanDefinition ) {
167
219
bd.autowireMode = autowireMode.ordinal
168
220
}
@@ -182,6 +234,10 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
182
234
* @param autowireMode Set the autowire mode, `Autowire.NO` by default
183
235
* @param isAutowireCandidate Set whether this bean is a candidate for getting
184
236
* autowired into some other bean.
237
+ * @param initMethodName Set the name of the initializer method
238
+ * @param destroyMethodName Set the name of the destroy method
239
+ * @param description Set a human-readable description of this bean definition
240
+ * @param role Set the role hint for this bean definition
185
241
* @param function the bean supplier function
186
242
* @see GenericApplicationContext.registerBean
187
243
* @see org.springframework.beans.factory.config.BeanDefinition
@@ -192,13 +248,21 @@ open class BeanDefinitionDsl(private val init: BeanDefinitionDsl.() -> Unit,
192
248
isPrimary : Boolean? = null,
193
249
autowireMode : Autowire = Autowire .NO ,
194
250
isAutowireCandidate : Boolean? = null,
251
+ initMethodName : String? = null,
252
+ destroyMethodName : String? = null,
253
+ description : String? = null,
254
+ role : Role = Role .APPLICATION ,
195
255
crossinline function : () -> T ) {
196
256
197
257
val customizer = BeanDefinitionCustomizer { bd ->
198
258
scope?.let { bd.scope = scope.name.toLowerCase() }
199
259
isLazyInit?.let { bd.isLazyInit = isLazyInit }
200
260
isPrimary?.let { bd.isPrimary = isPrimary }
201
261
isAutowireCandidate?.let { bd.isAutowireCandidate = isAutowireCandidate }
262
+ initMethodName?.let { bd.initMethodName = initMethodName }
263
+ destroyMethodName?.let { bd.destroyMethodName = destroyMethodName }
264
+ description?.let { bd.description = description }
265
+ bd.role = role.ordinal
202
266
if (bd is AbstractBeanDefinition ) {
203
267
bd.autowireMode = autowireMode.ordinal
204
268
}
0 commit comments