Skip to content

Commit b52a50a

Browse files
committed
Use Kotlin extensions for ClassPathXmlApplicationContext refdoc
Closes gh-23456
1 parent 4123910 commit b52a50a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,13 @@ example shows:
367367
.Kotlin
368368
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
369369
----
370+
import org.springframework.beans.factory.getBean
371+
370372
// create and configure beans
371373
val context = ClassPathXmlApplicationContext("services.xml", "daos.xml")
372374
373375
// retrieve configured instance
374-
val service = context.getBean("petStore", PetStoreService::class.java)
376+
val service = context.getBean<PetStoreService>("petStore")
375377
376378
// use configured instance
377379
var userList = service.getUsernameList()
@@ -4356,7 +4358,7 @@ The following Java application runs the preceding code and configuration:
43564358
43574359
public static void main(final String[] args) throws Exception {
43584360
ApplicationContext ctx = new ClassPathXmlApplicationContext("scripting/beans.xml");
4359-
Messenger messenger = (Messenger) ctx.getBean("messenger");
4361+
Messenger messenger = ctx.getBean("messenger", Messenger.class);
43604362
System.out.println(messenger);
43614363
}
43624364
@@ -4365,9 +4367,11 @@ The following Java application runs the preceding code and configuration:
43654367
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
43664368
.Kotlin
43674369
----
4370+
import org.springframework.beans.factory.getBean
4371+
43684372
fun main() {
43694373
val ctx = ClassPathXmlApplicationContext("scripting/beans.xml")
4370-
val messenger = ctx.getBean("messenger") as Messenger
4374+
val messenger = ctx.getBean<Messenger>("messenger")
43714375
println(messenger)
43724376
}
43734377
----

0 commit comments

Comments
 (0)