Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.config

public Class ProviderCreatingFactoryBean

extends AbstractFactoryBean<Provider<Object>>
Class Inheritance
Imports
java.io.Serializable, jakarta.inject.Provider, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, org.springframework.lang.Nullable, org.springframework.util.Assert

A org.springframework.beans.factory.FactoryBean implementation that returns a value which is a JSR-330 jakarta.inject.Provider that in turn returns a bean sourced from a org.springframework.beans.factory.BeanFactory.

This is basically a JSR-330 compliant variant of Spring's good old ObjectFactoryCreatingFactoryBean. It can be used for traditional external dependency injection configuration that targets a property or constructor argument of type jakarta.inject.Provider, as an alternative to JSR-330's @Inject annotation-driven approach.

Author
Juergen Hoeller
Since
3.0.2
See Also
jakarta.inject.Provider, ObjectFactoryCreatingFactoryBean

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ProviderCreatingFactoryBean.TargetBeanProvider

Independent inner class - for serialization purposes.

Field Summary

Modifier and TypeField and Description
private String
Inherited from org.springframework.beans.factory.config.AbstractFactoryBean:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
protected Provider<Object>
createInstance()

Implements abstract org.springframework.beans.factory.config.AbstractFactoryBean.createInstance.

Template method that subclasses must override to construct the object returned by this factory.

public Class<?>
getObjectType()

Implements abstract org.springframework.beans.factory.config.AbstractFactoryBean.getObjectType.

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

This abstract method declaration mirrors the method in the FactoryBean interface, for a consistent offering of abstract template methods.

public void
setTargetBeanName(String targetBeanName)

Set the name of the target bean.

Inherited from org.springframework.beans.factory.config.AbstractFactoryBean:
destroydestroyInstancegetBeanFactorygetBeanTypeConvertergetEarlySingletonInterfacesgetObjectisSingletonsetBeanClassLoadersetBeanFactorysetSingleton

Field Detail

targetBeanNameback to summary
private String targetBeanName
Annotations
@Nullable

Constructor Detail

ProviderCreatingFactoryBeanback to summary
public ProviderCreatingFactoryBean()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws Exception

Overrides org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet.

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet.

Eagerly create the singleton instance, if necessary.

Annotations
@Override
Exceptions
Exception:

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason

createInstanceback to summary
protected Provider<Object> createInstance()

Implements abstract org.springframework.beans.factory.config.AbstractFactoryBean.createInstance.

Doc from org.springframework.beans.factory.config.AbstractFactoryBean.createInstance.

Template method that subclasses must override to construct the object returned by this factory.

Invoked on initialization of this FactoryBean in case of a singleton; else, on each getObject() call.

Returns:Provider<Object>

the object returned by this factory

Annotations
@Override
getObjectTypeback to summary
public Class<?> getObjectType()

Implements abstract org.springframework.beans.factory.config.AbstractFactoryBean.getObjectType.

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

Doc from org.springframework.beans.factory.config.AbstractFactoryBean.getObjectType.

This abstract method declaration mirrors the method in the FactoryBean interface, for a consistent offering of abstract template methods.

Returns:Class<?>

Doc from org.springframework.beans.factory.FactoryBean.getObjectType.

the type of object that this FactoryBean creates, or null if not known at the time of the call

Annotations
@Override
setTargetBeanNameback to summary
public void setTargetBeanName(String targetBeanName)

Set the name of the target bean.

The target does not have to be a non-singleton bean, but realistically always will be (because if the target bean were a singleton, then said singleton bean could simply be injected straight into the dependent object, thus obviating the need for the extra level of indirection afforded by this factory approach).

org.springframework.beans.factory.config back to summary

private Class ProviderCreatingFactoryBean.TargetBeanProvider

extends Object
implements Provider<Object>, Serializable
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.config.ProviderCreatingFactoryBean.TargetBeanProvider
All Implemented Interfaces
java.io.Serializable, jakarta.inject.Provider
Annotations
@SuppressWarnings:serial

Independent inner class - for serialization purposes.

Field Summary

Modifier and TypeField and Description
private final BeanFactory
private final String

Constructor Summary

AccessConstructor and Description
public
TargetBeanProvider(BeanFactory beanFactory, String targetBeanName)

Method Summary

Modifier and TypeMethod and Description
public Object
get()

Implements jakarta.inject.Provider.get.

Provides a fully-constructed and injected instance of T.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanFactoryback to summary
private final BeanFactory beanFactory
targetBeanNameback to summary
private final String targetBeanName

Constructor Detail

TargetBeanProviderback to summary
public TargetBeanProvider(BeanFactory beanFactory, String targetBeanName)

Method Detail

getback to summary
public Object get() throws BeansException

Implements jakarta.inject.Provider.get.

Doc from jakarta.inject.Provider.get.

Provides a fully-constructed and injected instance of T.

Returns:Object

instance of T.

Annotations
@Override