This will fail to start with: ```Description: A co...
# spring
c
This will fail to start with:
Copy code
Description:
A component required a bean of type 'java.util.List' that could not be found.
Action:
Consider defining a bean of type 'java.util.List' in your configuration.
Why is that? Doesn't collection autowiring work with Spring Fu?
n
there’s no autowiring with spring fu everything needs to be explicitly declared
SomeConsumer
requires a list you need to create a dedicated bean of type
List<Some>
by yourself and provide it to the context
c
Ugh, that's ugly. So if we look at something like command handlers, in addition to defining each
bean<_Handler>()
one has to define a
bean<List<CommandHandler>> { listOf(ref<_Handler>(), ref<_Handler>(),...) }
?
n
exactly you wanted explicit, now you have it 😉
c
That's not entirely true, though. For example:
Copy code
MyClass(private val props: MyProps)
application {
  beans {
    configurationProperties<MyProps>()
    bean<MyClass>()
  }
}
works exactly as one would expect,
props
param is autowired. That's why I'm baffled, single dependencies are wired in, while collections of beans aren't. There's explicit, and then there is "do everything by hand, who needs frameworks di containers". The list stuff falls into the latter category, IMO.
n
props
param is autowired
because it’s found in the context
honestly, i fail to understand the pushback against “magic” the opposite is do-everything-by-hand which was the case before spring boot when it took me 2 days to kick start a project so my team could start developing now it’s 5-minutes trade-off 😄
c
One thing would be faster startup, sometimes it makes sense. In the project I'm encountering this issue, though, the reason for using spring-fu is: I want to play with spring-fu 🙂
n
I want to play with spring-fu 🙂
great! remember though it’s an experimental sandbox
c
I do, it doesn't invalidate my question though 🙂
n
which one?
about the list not being created under the hood?
c
Maybe I should've phrased it as "Is this by design, and if so, why? I thought that injecting collections of beans was handled by context and we have context in spring fu, same as in normal Spring Boot"
And if this really is by design, I'd add some helper, which would eliminate adding beans to a list by hand. E.g.
bean<List<Some>>(gatherBeans=true)
or something
n
@sdeleuze is the guy to talk to in that case
c
Ok, this is explicit enough and it works 🙂 Seems I was partially right 🙂
Copy code
beans {
  bean {
    SomeConsumer(provider<Some>().toList())
  }
}
👍 1
n
well done