Top Description Fields Constructors Methods
org.springframework.beans.factory.support

public Class SimpleInstantiationStrategy

extends Object
implements InstantiationStrategy
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.support.InstantiationStrategy
Known Direct Subclasses
org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy
Imports
java.lang.reflect.Constructor, .InvocationTargetException, .Method, org.springframework.beans.BeanInstantiationException, .BeanUtils, org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.config.ConfigurableBeanFactory, org.springframework.lang.Nullable, org.springframework.util.ReflectionUtils, .StringUtils

Simple object instantiation strategy for use in a BeanFactory.

Does not support Method Injection, although it provides hooks for subclasses to override to add Method Injection support, for example by overriding methods.

Authors
Rod Johnson, Juergen Hoeller, Stephane Nicoll
Since
1.1

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<Method>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Method
getCurrentlyInvokedFactoryMethod()

Return the factory method currently being invoked or null if none.

public Object
instantiate(RootBeanDefinition
the bean definition
bd
,
String
the name of the bean when it is created in this context. The name can be null if we are autowiring a bean which doesn't belong to the factory.
beanName
,
BeanFactory
the owning BeanFactory
owner
)

Implements org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Return an instance of the bean with the given name in this factory.

public Object
instantiate(RootBeanDefinition
the bean definition
bd
,
String
the name of the bean when it is created in this context. The name can be null if we are autowiring a bean which doesn't belong to the factory.
beanName
,
BeanFactory
the owning BeanFactory
owner
,
Constructor<?>
the constructor to use
ctor
,
Object...
the constructor arguments to apply
args
)

Implements org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Return an instance of the bean with the given name in this factory, creating it via the given constructor.

public Object
instantiate(RootBeanDefinition
the bean definition
bd
,
String
the name of the bean when it is created in this context. The name can be null if we are autowiring a bean which doesn't belong to the factory.
beanName
,
BeanFactory
the owning BeanFactory
owner
,
Object
the factory bean instance to call the factory method on, or null in case of a static factory method
factoryBean
,
Method
the factory method to use
factoryMethod
,
Object...
the factory method arguments to apply
args
)

Implements org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Return an instance of the bean with the given name in this factory, creating it via the given factory method.

protected Object
instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner)

Subclasses can override this method, which is implemented to throw UnsupportedOperationException, if they can instantiate an object with the Method Injection specified in the given RootBeanDefinition.

protected Object
instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner, Constructor<?> ctor, Object... args)

Subclasses can override this method, which is implemented to throw UnsupportedOperationException, if they can instantiate an object with the Method Injection specified in the given RootBeanDefinition.

public static void
setCurrentlyInvokedFactoryMethod(Method
the factory method currently being invoked or null
method
)

Set the factory method currently being invoked or null to reset.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentlyInvokedFactoryMethodback to summary
private static final ThreadLocal<Method> currentlyInvokedFactoryMethod

Constructor Detail

SimpleInstantiationStrategyback to summary
public SimpleInstantiationStrategy()

Method Detail

getCurrentlyInvokedFactoryMethodback to summary
public static Method getCurrentlyInvokedFactoryMethod()

Return the factory method currently being invoked or null if none.

Allows factory method implementations to determine whether the current caller is the container itself as opposed to user code.

Annotations
@Nullable
instantiateback to summary
public Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner)

Implements org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Doc from org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Return an instance of the bean with the given name in this factory.

Parameters
bd:RootBeanDefinition

the bean definition

beanName:String

the name of the bean when it is created in this context. The name can be null if we are autowiring a bean which doesn't belong to the factory.

owner:BeanFactory

the owning BeanFactory

Returns:Object

a bean instance for this bean definition

Annotations
@Override
instantiateback to summary
public Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner, Constructor<?> ctor, Object... args)

Implements org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Doc from org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Return an instance of the bean with the given name in this factory, creating it via the given constructor.

Parameters
bd:RootBeanDefinition

the bean definition

beanName:String

the name of the bean when it is created in this context. The name can be null if we are autowiring a bean which doesn't belong to the factory.

owner:BeanFactory

the owning BeanFactory

ctor:Constructor<?>

the constructor to use

args:Object[]

the constructor arguments to apply

Returns:Object

a bean instance for this bean definition

Annotations
@Override
instantiateback to summary
public Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner, Object factoryBean, Method factoryMethod, Object... args)

Implements org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Doc from org.springframework.beans.factory.support.InstantiationStrategy.instantiate.

Return an instance of the bean with the given name in this factory, creating it via the given factory method.

Parameters
bd:RootBeanDefinition

the bean definition

beanName:String

the name of the bean when it is created in this context. The name can be null if we are autowiring a bean which doesn't belong to the factory.

owner:BeanFactory

the owning BeanFactory

factoryBean:Object

the factory bean instance to call the factory method on, or null in case of a static factory method

factoryMethod:Method

the factory method to use

args:Object[]

the factory method arguments to apply

Returns:Object

a bean instance for this bean definition

Annotations
@Override
instantiateWithMethodInjectionback to summary
protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner)

Subclasses can override this method, which is implemented to throw UnsupportedOperationException, if they can instantiate an object with the Method Injection specified in the given RootBeanDefinition. Instantiation should use a no-arg constructor.

instantiateWithMethodInjectionback to summary
protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner, Constructor<?> ctor, Object... args)

Subclasses can override this method, which is implemented to throw UnsupportedOperationException, if they can instantiate an object with the Method Injection specified in the given RootBeanDefinition. Instantiation should use the given constructor and parameters.

setCurrentlyInvokedFactoryMethodback to summary
public static void setCurrentlyInvokedFactoryMethod(Method method)

Set the factory method currently being invoked or null to reset.

Parameters
method:Method

the factory method currently being invoked or null

Since
6.0