@@ -367,11 +367,13 @@ example shows:
367
367
.Kotlin
368
368
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
369
369
----
370
+ import org.springframework.beans.factory.getBean
371
+
370
372
// create and configure beans
371
373
val context = ClassPathXmlApplicationContext("services.xml", "daos.xml")
372
374
373
375
// retrieve configured instance
374
- val service = context.getBean("petStore", PetStoreService::class.java )
376
+ val service = context.getBean<PetStoreService> ("petStore")
375
377
376
378
// use configured instance
377
379
var userList = service.getUsernameList()
@@ -4356,7 +4358,7 @@ The following Java application runs the preceding code and configuration:
4356
4358
4357
4359
public static void main(final String[] args) throws Exception {
4358
4360
ApplicationContext ctx = new ClassPathXmlApplicationContext("scripting/beans.xml");
4359
- Messenger messenger = (Messenger) ctx.getBean("messenger");
4361
+ Messenger messenger = ctx.getBean("messenger", Messenger.class );
4360
4362
System.out.println(messenger);
4361
4363
}
4362
4364
@@ -4365,9 +4367,11 @@ The following Java application runs the preceding code and configuration:
4365
4367
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
4366
4368
.Kotlin
4367
4369
----
4370
+ import org.springframework.beans.factory.getBean
4371
+
4368
4372
fun main() {
4369
4373
val ctx = ClassPathXmlApplicationContext("scripting/beans.xml")
4370
- val messenger = ctx.getBean("messenger") as Messenger
4374
+ val messenger = ctx.getBean<Messenger> ("messenger")
4371
4375
println(messenger)
4372
4376
}
4373
4377
----
0 commit comments