Skip to content

Instantly share code, notes, and snippets.

@maslick
Last active April 20, 2018 08:34
Show Gist options
  • Save maslick/861aed6b5a0313364d5b761327360556 to your computer and use it in GitHub Desktop.
Save maslick/861aed6b5a0313364d5b761327360556 to your computer and use it in GitHub Desktop.
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.context.support.beans
import org.springframework.stereotype.Component
interface Yoyo {
fun haha() {
println("hello world")
}
}
@Component class Yoyo1 : Yoyo
@Component class Yoyo2 : Yoyo
@Component class Yoyo3 : Yoyo
@Component class YoyoN : Yoyo
@SpringBootApplication
class YoyoApp
fun main(args: Array<String>) {
SpringApplicationBuilder()
.sources(YoyoApp::class.java)
.initializers(beans {
bean {
CommandLineRunner {
val y1 = ref<Yoyo1>()
val y2 = ref<Yoyo2>()
val y3 = ref<Yoyo3>()
val yN = ref<YoyoN>()
arrayOf(y1, y2, y3, yN).forEach { it.haha() }
}
}
})
.run(*args)
}
@Component
class Hoho : CommandLineRunner {
@Autowired
lateinit var list: List<Yoyo>
override fun run(vararg args: String?) {
list.forEach { it.haha() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment