Is it somehow possible to define this `init` bean ...
# spring
i
Is it somehow possible to define this
init
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
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
Copy code
@Component
class MyInitThing(repository: StreamRepository) : ApplicationRunner {
  ...
}