This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Spring In Action 5th Edition Question  RSS feed

 
Ranch Hand
Posts: 447
Java jQuery Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Does Spring 5 allow you to inject a lambda into a bean via configuration?
 
author
Posts: 396
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?

 
Ranch Hand
Posts: 198
1
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never personally used, but I have seen some examples around ...

Spring 4 on Java 8


 
meenakshi sundar
Ranch Hand
Posts: 198
1
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another interesting read on the functional web framework...

functional-web-framework
 
Craig Walls
author
Posts: 396
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ...

Spring 4 on Java 8


 
Craig Walls
author
Posts: 396
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, another great example of using functions (lambdas or method references) in Spring. In fact, I cover this in the book, as well.

meenakshi sundar wrote:Another interesting read on the functional web framework...

functional-web-framework

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!