bean as top-level function? (now this bean does not run)
Copy code
@SpringBootApplication
class TestServerApplication
fun main(args: Array<String>) {
runApplication<TestServerApplication>(*args)
}
@Bean
fun init(repository: StreamRepository) = ApplicationRunner { _ ->
// Do sth on app start
}
This makes a bean run, but this solution involves a lot of nesting, so wonder if this is necessary 🤔
Copy code
@SpringBootApplication
class InboxionServerApplication {
companion object {
@JvmStatic
fun main(args: Array<String>) {
runApplication<InboxionServerApplication>(*args)
}
}
@Bean
fun init(repository: StreamRepository) = ApplicationRunner { _ ->
// Do sth on app start
}
}
t
Tobias Berger
02/26/2021, 8:18 AM
AFAIK a Bean definition in Spring has to be a member of a configuration component. But I don't see what you mean with "a lot of nesting". Putting the init function into a class just puts it one layer deeper - something you basically do all the time when you write any class.
j
Joel
03/01/2021, 10:25 PM
Copy code
@Component
class MyInitThing(repository: StreamRepository) : ApplicationRunner {
...
}