Out of curiosity, did anyone of you play around wi...
# spring
p
Out of curiosity, did anyone of you play around with supplying lambdas as beans? I’m talking about the following:
Copy code
@Configuration
class MyConfig {
    @Bean
    fun sendAnEmail(emailPublisher: EmailPubSubPublisher) = sendAnEmailLambdaVersion(emailPublisher)
}

fun sendAnEmailLambdaVersion(emailPublisher: EmailPubSubPublisher): (SomeEmail) -> Mono<String> =
    { email: SomeEmail -> emailPublisher.send(email) }
sure it works, but throwing
@Bean
on the function directly would be ofc more elegant, but I’m currently making no progress in that direction. Does anyone have any experience with that? Thanks! 🙂
s
We do this a lot for spring cloud streams, we would normally write this as:
Copy code
@Bean
fun sendAnEmail(emailPublisher: ...): (SomeEmail) -> Mono<String> = { emailPublisher.send(it) }
p
I’m really curious why Beans on functions is only integrated in spring cloud streams, but not in Spring Core. 🤔
s
I believe it comes from
spring-cloud-function-kotlin
rather than streams
Alternatively, I think using the Java interfaces work and then you can use SAM interfaces?
Copy code
@Bean
fun sendAnEmail(emailPublisher: ...): Function<SomeEmail, MonoString> = Function { ... }
p
Seems like I gotta dig more into that..
👍 1