It depends on how you do configuration, but yes. Certainly, there's no way to do it with XML config. But if you are using JavaConfig and the bean you're creating requires a functional type, then there's no reason you couldn't just pass a lambda or method reference into the setter or constructor arg.
On the other hand, if you're asking if it's possible to declare a lambda as a bean, then I'm not so sure. I'd wonder what that would even look like. i suppose that it'd be possible to manually register a lambda as a bean by calling registerBean() on a given GenericApplicationContext, but I can't say that I've tried it. (I have used Lambdas to define a bean of a given type when calling registerBean(), but never have had the bean itself be defined as a Lambda.)
Will Myers wrote:Hi,
Does Spring 5 allow you to inject a lambda into a bean via configuration?
Yes, this is a good example, I often use lambdas or method references in place of a RowMapper when working with JdbcTemplate (in fact, I cover this in the book). I wasn't thinking of that use of lambdas as being DI, though...although I guess you could say that they are. I was thinking more of how you'd inject a lambda in the context of a configuration class.
meenakshi sundar wrote:I have never personally used, but I have seen some examples around ...