You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for Supplier as a deferred bean creation [SPR-16973] #21511
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
It would be even nicer if there was a way to ask the BeanFactory directly for a Supplier because this could be used in functional bean registrations to make lazy assignments like the above. You can create the example above with bean registrations by making the configuration class implement BeanDefinitionRegistry (and removing the @Bean annotations):
It works, but a) it's a bit ugly, and b) I would like to be able to use @Configuration classes to create bean definitions in the functional style, like the above, but I can't do it without using Provider in place of Supplier, and therefore I need JSR-330 on the classpath.
I could also achieve this goal if there was a way to use ObjectProvider in place of Supplier, but there isn't really because it's kind of an internal interface. And it's not functional of course. I ended up working round that by creating some convenience factories for ObjectProvider (they need a Method so they can inspect the generic type of the provider).
The BeanFactory perhaps could make this pattern more of a first class concept. Kind of off topic for the original issue here, but just showing some of what I have been thinking about.
Spring already has ObjectFactory which is a functional interface that supports the pattern above. It's better than Supplier because it has additional instance creation semantics (only once per singleton).
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Activity
spring-projects-issues commentedon Jun 25, 2018
Dave Syer commented
It would be even nicer if there was a way to ask the
BeanFactorydirectly for aSupplierbecause this could be used in functional bean registrations to make lazy assignments like the above. You can create the example above with bean registrations by making the configuration class implementBeanDefinitionRegistry(and removing the@Beanannotations):It works, but a) it's a bit ugly, and b) I would like to be able to use
@Configurationclasses to create bean definitions in the functional style, like the above, but I can't do it without usingProviderin place ofSupplier, and therefore I need JSR-330 on the classpath.I could also achieve this goal if there was a way to use
ObjectProviderin place ofSupplier, but there isn't really because it's kind of an internal interface. And it's not functional of course. I ended up working round that by creating some convenience factories forObjectProvider(they need aMethodso they can inspect the generic type of the provider).The
BeanFactoryperhaps could make this pattern more of a first class concept. Kind of off topic for the original issue here, but just showing some of what I have been thinking about.spring-projects-issues commentedon Jul 23, 2018
Dave Syer commented
Spring already has
ObjectFactorywhich is a functional interface that supports the pattern above. It's better thanSupplierbecause it has additional instance creation semantics (only once per singleton).