File tree 2 files changed +15
-12
lines changed
main/kotlin/org/springframework/context/support
test/kotlin/org/springframework/context/support 2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 17
17
package org.springframework.context.support
18
18
19
19
import org.springframework.beans.factory.config.BeanDefinitionCustomizer
20
+ import org.springframework.context.ApplicationContextInitializer
20
21
import org.springframework.core.env.ConfigurableEnvironment
21
22
import java.util.function.Supplier
22
23
@@ -75,7 +76,7 @@ fun beans(init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
75
76
* @author Sebastien Deleuze
76
77
* @since 5.0
77
78
*/
78
- class BeanDefinitionDsl (private val condition : (ConfigurableEnvironment ) -> Boolean = { true }) : ( GenericApplicationContext ) -> Unit {
79
+ class BeanDefinitionDsl (private val condition : (ConfigurableEnvironment ) -> Boolean = { true }) : ApplicationContextInitializer< GenericApplicationContext> {
79
80
80
81
@PublishedApi
81
82
internal val registrations = arrayListOf< (GenericApplicationContext ) -> Unit > ()
@@ -210,17 +211,17 @@ class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) -> Bool
210
211
}
211
212
212
213
/* *
213
- * Register the bean defined via the DSL on thAh pe provided application context.
214
+ * Register the bean defined via the DSL on the provided application context.
214
215
* @param context The `ApplicationContext` to use for registering the beans
215
216
*/
216
- override fun invoke (context : GenericApplicationContext ) {
217
+ override fun initialize (context : GenericApplicationContext ) {
217
218
for (registration in registrations) {
218
219
if (condition.invoke(context.environment)) {
219
220
registration.invoke(context)
220
221
}
221
222
}
222
223
for (child in children) {
223
- child.invoke (context)
224
+ child.initialize (context)
224
225
}
225
226
}
226
227
}
Original file line number Diff line number Diff line change @@ -36,9 +36,10 @@ class BeanDefinitionDslTests {
36
36
bean { Baz (ref(" bar" )) }
37
37
}
38
38
39
- val context = GenericApplicationContext ()
40
- beans.invoke(context)
41
- context.refresh()
39
+ val context = GenericApplicationContext ().apply {
40
+ beans.initialize(this )
41
+ refresh()
42
+ }
42
43
43
44
assertNotNull(context.getBean<Foo >())
44
45
assertNotNull(context.getBean<Bar >(" bar" ))
@@ -60,9 +61,10 @@ class BeanDefinitionDslTests {
60
61
}
61
62
}
62
63
63
- val context = GenericApplicationContext ()
64
- beans.invoke(context)
65
- context.refresh()
64
+ val context = GenericApplicationContext ().apply {
65
+ beans.initialize(this )
66
+ refresh()
67
+ }
66
68
67
69
assertNotNull(context.getBean<Foo >())
68
70
assertNotNull(context.getBean<Bar >(" bar" ))
@@ -87,9 +89,9 @@ class BeanDefinitionDslTests {
87
89
88
90
val context = GenericApplicationContext ().apply {
89
91
environment.propertySources.addFirst(SimpleCommandLinePropertySource (" --name=foofoo" ))
92
+ beans.initialize(this )
93
+ refresh()
90
94
}
91
- beans.invoke(context)
92
- context.refresh()
93
95
94
96
assertNotNull(context.getBean<Foo >())
95
97
assertNotNull(context.getBean<Bar >(" bar" ))
You can’t perform that action at this time.
0 commit comments