public final class GeneratedBeanDefinitions extends java.lang.Object
What the code generated ahead of time did for the beans it contributed, so that the processors injecting through annotations do not do it a second time.
An application running on generated artifacts has those processors registered again, for the annotated
members the generated code could not see. The generated code injects a bean through the annotated members of
the type its definition declares, and records that type's initialization and destruction methods on the
definition; injected a second time, a bean runs a side-effecting @Autowired method twice, which
registered every executor's metrics twice.
The code generated for each definition, an inner bean's included, calls markGenerated as it returns the definition. That names on the definition the type whose members the code injects, and records each instance its supplier creates. A definition declared any other way carries no such name, wherever and whenever it is declared, so it is processed as usual.
For a bean whose definition names that type, the processors first mark the type's members as configured
from outside, with the methods of the bean's class overriding them, which are what the generated code
called. That is how Spring keeps two processors from injecting one member, so an instance the generated code
created is injected only through the members its class adds. Any other instance of the bean, such as one
handed to configureBean, was not injected by that code, and is processed in full.
The generated code also records on each definition the initialization and destruction methods it found annotated. Those are taken off again, since the processor that calls them is registered again and calls them for every instance: see leaveAnnotatedLifecycleMethodsToProcessor.
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
DECLARED_TYPE_ATTRIBUTE |
The attribute that names, on a definition the generated code contributed, the type that code injects. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static boolean |
isAnotherInstanceOfGeneratedBean(BeanFactory beanFactory, java.lang.String beanName, java.lang.Object bean)Whether an instance is not one the generated code created, although its bean's definition is a generated one: an instance handed to configureBean or initializeBean under that bean's name, which
the generated code injected nothing into. |
|
public static void |
leaveAnnotatedLifecycleMethodsToProcessor(BeanDefinitionRegistry registry)Takes off the definitions the generated code contributed, inner beans' included, the initialization and destruction methods that code recorded from annotations, once the processor that calls annotated ones is registered again. |
|
public static void |
markGenerated(RootBeanDefinition beanDefinition, java.lang.String declaredType)Marks a definition the generated code contributed: called by that code as it returns the definition. |
|
public static void |
markMembersInjectedByGeneratedCode(RootBeanDefinition beanDefinition, java.lang.Class<?> beanType, MergedBeanDefinitionPostProcessor generatingProcessor)Marks as configured from outside, on the merged definition of a bean the generated code contributed, the members that code injects: those the given processor finds on the type the definition names, and the methods of the bean's class overriding them, which are the ones the generated code called. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
The attribute that names, on a definition the generated code contributed, the type that code injects.
Whether an instance is not one the generated code created, although its bean's definition is a generated
one: an instance handed to configureBean or initializeBean under that bean's name, which
the generated code injected nothing into.
beanFactory - the bean factory the bean is inbeanName - the bean's namebean - the instancetrue when the bean's definition was contributed by the generated code and the instance
was not created by itTakes off the definitions the generated code contributed, inner beans' included, the initialization and destruction methods that code recorded from annotations, once the processor that calls annotated ones is registered again. That processor calls them for every instance, as on a context without generated code.
Left on, a recorded method ran twice for an instance handed to configureBean. The container
skips a recorded method that a processor has called, but configureBean works on a copy of the
definition, which keeps the recorded names and loses what the processor called.
registry - the registry the generated code contributed its definitions toMarks a definition the generated code contributed: called by that code as it returns the definition.
beanDefinition - the definition, with the instance supplier the generated code gave itdeclaredType - the name of the type whose annotated members the generated code injectsMarks as configured from outside, on the merged definition of a bean the generated code contributed, the members that code injects: those the given processor finds on the type the definition names, and the methods of the bean's class overriding them, which are the ones the generated code called. An override of a generic method is the method declared with the actual type, not the bridge the compiler adds for the erased one. A processor of that kind then injects an instance the generated code created only through the members its class adds, which is none when the class is the type the definition names.
beanDefinition - the bean's merged definition, before the processor of that kind processes itbeanType - the class of the beangeneratingProcessor - a processor of the kind and configuration the code was generated with, which
is given a definition of its own to process