com.tianyisoft.database.util.BeanHelper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of querybuilder Show documentation
Show all versions of querybuilder Show documentation
A query builder from laravel
The newest version!
package com.tianyisoft.database.util
import org.springframework.beans.factory.InitializingBean
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.stereotype.Component
@Component
class BeanHelper : ApplicationContextAware, InitializingBean {
private lateinit var applicationContext: ApplicationContext
override fun setApplicationContext(applicationContext: ApplicationContext) {
this.applicationContext = applicationContext
}
override fun afterPropertiesSet() {
beanHelper = this
}
companion object {
private var beanHelper: BeanHelper? = null
fun getBean(clazz: Class): T {
return beanHelper!!.applicationContext.getBean(clazz)
}
fun getBean(name: String): Any {
return beanHelper!!.applicationContext.getBean(name)
}
fun getBean(name: String, clazz: Class): T {
return beanHelper!!.applicationContext.getBean(name, clazz)
}
}
}