Top Description Fields Methods
org.springframework.beans.factory.aot

public Interface BeanRegistrationCodeFragments

Known Direct Implementers
org.springframework.beans.factory.aot.BeanRegistrationCodeFragmentsDecorator, org.springframework.beans.factory.aot.DefaultBeanRegistrationCodeFragments
Imports
java.util.List, java.util.function.Predicate, .UnaryOperator, org.springframework.aot.generate.GenerationContext, .MethodReference, org.springframework.beans.factory.support.InstanceSupplier, .RegisteredBean, .RootBeanDefinition, org.springframework.core.ResolvableType, org.springframework.javapoet.ClassName, .CodeBlock

Generate the various fragments of code needed to register a bean.

A default implementation is provided that suits most needs and custom code fragments are only expected to be used by library authors having built custom arrangement on top of the core container.

Users are not expected to implement this interface directly, but rather extends from BeanRegistrationCodeFragmentsDecorator and only override the necessary method(s).

Authors
Phillip Webb, Stephane Nicoll
Since
6.0
See Also
BeanRegistrationCodeFragmentsDecorator, BeanRegistrationAotContribution#withCustomCodeFragments(UnaryOperator)

Field Summary

Modifier and TypeField and Description
public static final String
BEAN_DEFINITION_VARIABLE

The variable name to used when creating the bean definition.

public static final String
INSTANCE_SUPPLIER_VARIABLE

The variable name to used when creating the bean definition.

Method Summary

Modifier and TypeMethod and Description
public CodeBlock

Returns:

the generated code
generateInstanceSupplierCode
(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
,
boolean
if direct suppliers may be used rather than always needing an InstanceSupplier
allowDirectSupplierShortcut
)

Generate the instance supplier code.

public CodeBlock

Returns:

the generated code
generateNewBeanDefinitionCode
(GenerationContext
the generation context
generationContext
,
ResolvableType
the bean type
beanType
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
)

Generate the code that defines the new bean definition instance.

public CodeBlock

Returns:

the generated code
generateReturnCode
(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
)

Generate the return statement.

public CodeBlock

Returns:

the generated code
generateSetBeanDefinitionPropertiesCode
(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
,
RootBeanDefinition beanDefinition, Predicate<String>
any attribute filtering that should be applied
attributeFilter
)

Generate the code that sets the properties of the bean definition.

public CodeBlock

Returns:

the generated code
generateSetBeanInstanceSupplierCode
(GenerationContext
the generation context
generationContext
,
BeanRegistrationCode
the bean registration code
beanRegistrationCode
,
CodeBlock
the instance supplier code supplier code
instanceSupplierCode
,
List<MethodReference>
any instance post processors that should be applied
postProcessors
)

Generate the code that sets the instance supplier on the bean definition.

public ClassName

Returns:

the target ClassName
getTarget
(RegisteredBean
the registered bean
registeredBean
)

Return the target for the registration.

Field Detail

BEAN_DEFINITION_VARIABLEback to summary
public static final String BEAN_DEFINITION_VARIABLE

The variable name to used when creating the bean definition.

INSTANCE_SUPPLIER_VARIABLEback to summary
public static final String INSTANCE_SUPPLIER_VARIABLE

The variable name to used when creating the bean definition.

Method Detail

generateInstanceSupplierCodeback to summary
public CodeBlock generateInstanceSupplierCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, boolean allowDirectSupplierShortcut)

Generate the instance supplier code.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

allowDirectSupplierShortcut:boolean

if direct suppliers may be used rather than always needing an InstanceSupplier

Returns:CodeBlock

the generated code

generateNewBeanDefinitionCodeback to summary
public CodeBlock generateNewBeanDefinitionCode(GenerationContext generationContext, ResolvableType beanType, BeanRegistrationCode beanRegistrationCode)

Generate the code that defines the new bean definition instance.

This should declare a variable named beanDefinition so that further fragments can refer to the variable to further tune the bean definition.

Parameters
generationContext:GenerationContext

the generation context

beanType:ResolvableType

the bean type

beanRegistrationCode:BeanRegistrationCode

the bean registration code

Returns:CodeBlock

the generated code

generateReturnCodeback to summary
public CodeBlock generateReturnCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode)

Generate the return statement.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

Returns:CodeBlock

the generated code

generateSetBeanDefinitionPropertiesCodeback to summary
public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter)

Generate the code that sets the properties of the bean definition.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

attributeFilter:Predicate<String>

any attribute filtering that should be applied

Returns:CodeBlock

the generated code

generateSetBeanInstanceSupplierCodeback to summary
public CodeBlock generateSetBeanInstanceSupplierCode(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode, List<MethodReference> postProcessors)

Generate the code that sets the instance supplier on the bean definition.

The postProcessors represent methods to be exposed once the instance has been created to further configure it. Each method should accept two parameters, the RegisteredBean and the bean instance, and should return the modified bean instance.

Parameters
generationContext:GenerationContext

the generation context

beanRegistrationCode:BeanRegistrationCode

the bean registration code

instanceSupplierCode:CodeBlock

the instance supplier code supplier code

postProcessors:List<MethodReference>

any instance post processors that should be applied

Returns:CodeBlock

the generated code

See Also
generateInstanceSupplierCode
getTargetback to summary
public ClassName getTarget(RegisteredBean registeredBean)

Return the target for the registration. Used to determine where to write the code. This should take into account visibility issue, such as package access of an element of the bean to register.

Parameters
registeredBean:RegisteredBean

the registered bean

Returns:ClassName

the target ClassName