Skip to content

Commit

Permalink
Use Kotlin extensions for ClassPathXmlApplicationContext refdoc
Browse files Browse the repository at this point in the history
Closes gh-23456
  • Loading branch information
sdeleuze committed Aug 13, 2019
1 parent 4123910 commit b52a50a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/docs/asciidoc/core/core-beans.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ example shows:
.Kotlin
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
----
import org.springframework.beans.factory.getBean
// create and configure beans
val context = ClassPathXmlApplicationContext("services.xml", "daos.xml")
// retrieve configured instance
val service = context.getBean("petStore", PetStoreService::class.java)
val service = context.getBean<PetStoreService>("petStore")
// use configured instance
var userList = service.getUsernameList()
Expand Down Expand Up @@ -4356,7 +4358,7 @@ The following Java application runs the preceding code and configuration:
public static void main(final String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("scripting/beans.xml");
Messenger messenger = (Messenger) ctx.getBean("messenger");
Messenger messenger = ctx.getBean("messenger", Messenger.class);
System.out.println(messenger);
}
Expand All @@ -4365,9 +4367,11 @@ The following Java application runs the preceding code and configuration:
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
import org.springframework.beans.factory.getBean
fun main() {
val ctx = ClassPathXmlApplicationContext("scripting/beans.xml")
val messenger = ctx.getBean("messenger") as Messenger
val messenger = ctx.getBean<Messenger>("messenger")
println(messenger)
}
----
Expand Down

0 comments on commit b52a50a

Please sign in to comment.