ron
03/13/2017, 8:16 PMxml
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld">
<property name = "message" value = "Hello World!"/>
</bean>
The bean is then accessible using the id
. This can be done in tornadoFX too:
kotlin
class SpringExampleApp : App(SpringExampleView::class) {
init {
val springContext = ClassPathXmlApplicationContext("beans.xml")
FX.dicontainer = object : DIContainer {
override fun <T : Any> getInstance(type: KClass<T>): T = springContext.getBean(type.java)
override fun <T : Any> getInstance(type: KClass<T>, name: String): T = springContext.getBean(type.java,name)
}
}
}
The second getInstance
uses both the type of the bean and the id of the bean. Instantiating a bean is down as:
val helloBean : HelloBean by di("helloWorld")