Configuration classes by generating a CGLIB subclass which
interacts with the Spring container to respect bean scoping semantics for
@Bean methods. Each such @Bean method will be overridden in
the generated subclass, only delegating to the actual @Bean method
implementation if the container actually requests the construction of a new
instance. Otherwise, a call to such an @Bean method serves as a
reference back to the container, obtaining the corresponding bean by name.
enhance, ConfigurationClassPostProcessor
| Modifier and Type | Class and Description |
|---|---|
| private static class | ConfigurationClassEnhancer.BeanFactoryAwareGeneratorStrategy
Custom extension of CGLIB's DefaultGeneratorStrategy, introducing a |
| private static class | ConfigurationClassEnhancer.BeanFactoryAwareMethodInterceptor
Intercepts the invocation of any |
| private static class | ConfigurationClassEnhancer.BeanMethodInterceptor
Intercepts the invocation of any |
| private static interface | |
| private static class | ConfigurationClassEnhancer.ConditionalCallbackFilter
A |
| public static interface | ConfigurationClassEnhancer.EnhancedConfiguration
Marker interface to be implemented by all @Configuration CGLIB subclasses. |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final ConfigurationClassEnhancer. | |
| pack-priv static final Callback[] | |
| private static final Log | |
| private static final SpringObjenesis |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private Class | createClass(Enhancer enhancer)
Uses enhancer to generate a subclass of superclass, ensuring that callbacks are registered for the new subclass. |
| public Class | Returns: the enhanced subclassLoads the specified class and generates a CGLIB subclass of it equipped with container-aware callbacks capable of respecting scoping and other bean semantics. |
| private Enhancer | newEnhancer(Class<?> configSuperClass, ClassLoader classLoader)
Creates a new CGLIB |
| BEAN_FACTORY_FIELD | back to summary |
|---|---|
| private static final String BEAN_FACTORY_FIELD | |
| CALLBACK_FILTER | back to summary |
|---|---|
| private static final ConfigurationClassEnhancer. | |
| CALLBACKS | back to summary |
|---|---|
| pack-priv static final Callback[] CALLBACKS | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| objenesis | back to summary |
|---|---|
| private static final SpringObjenesis objenesis | |
| ConfigurationClassEnhancer | back to summary |
|---|---|
| pack-priv ConfigurationClassEnhancer() | |
| createClass | back to summary |
|---|---|
| private Class Uses enhancer to generate a subclass of superclass, ensuring that callbacks are registered for the new subclass. | |
| enhance | back to summary |
|---|---|
| public Class Loads the specified class and generates a CGLIB subclass of it equipped with container-aware callbacks capable of respecting scoping and other bean semantics.
| |
| newEnhancer | back to summary |
|---|---|
| private Enhancer newEnhancer(Class<?> configSuperClass, ClassLoader classLoader) Creates a new CGLIB | |
BeanFactory field.
Also exposes the application ClassLoader as thread context ClassLoader for the time of
class generation (in order for ASM to pick it up when doing common superclass resolution).
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected ClassGenerator |
| BeanFactoryAwareGeneratorStrategy | back to summary |
|---|---|
| public BeanFactoryAwareGeneratorStrategy(ClassLoader classLoader) | |
| transform | back to summary |
|---|---|
| protected ClassGenerator transform(ClassGenerator cg) throws Exception Overrides org.
| |
BeanFactoryAware#setBeanFactory(BeanFactory) on
@Configuration class instances for the purpose of recording the BeanFactory.
EnhancedConfiguration
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Object | intercept(Object
"this", the enhanced object obj, Method intercepted Method method, Object[] argument array; primitive types are wrapped args, MethodProxy used to invoke super (non-intercepted method); may be called
as many times as needed proxy)Implements org. |
| public boolean | isMatch(Method candidateMethod)
Implements org. |
| public static boolean |
| BeanFactoryAwareMethodInterceptor | back to summary |
|---|---|
| private BeanFactoryAwareMethodInterceptor() | |
| intercept | back to summary |
|---|---|
| public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable Implements org. Doc from org. All generated proxied methods call this method instead of the original method. The original method may either be invoked by normal reflection using the Method object, or by using the MethodProxy (faster).
| |
| isMatch | back to summary |
|---|---|
| public boolean isMatch(Method candidateMethod) Implements org.
| |
| isSetBeanFactory | back to summary |
|---|---|
| public static boolean isSetBeanFactory(Method candidateMethod) | |
Bean-annotated methods in order to ensure proper
handling of bean semantics such as scoping and AOP proxying.
Bean, ConfigurationClassEnhancer
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private Object | createCglibProxyForFactoryBean(Object factoryBean, ConfigurableBeanFactory beanFactory, String beanName)
|
| private Object | createInterfaceProxyForFactoryBean(Object factoryBean, Class<?> interfaceType, ConfigurableBeanFactory beanFactory, String beanName)
|
| private Object | enhanceFactoryBean(Object factoryBean, Class<?> exposedType, ConfigurableBeanFactory beanFactory, String beanName)
Create a subclass proxy that intercepts calls to getObject(), delegating to the current BeanFactory instead of creating a new instance. |
| private boolean | Returns: whether beanName already exists in the factoryname of bean to check for beanName)Check the BeanFactory to see whether the bean named beanName already exists. |
| private ConfigurableBeanFactory | |
| public Object | intercept(Object
"this", the enhanced object enhancedConfigInstance, Method intercepted Method beanMethod, Object[] argument array; primitive types are wrapped beanMethodArgs, MethodProxy used to invoke super (non-intercepted method); may be called
as many times as needed cglibMethodProxy)Implements org. @Bean method to check the supplied BeanFactory for the
existence of this bean object.
|
| private boolean | isCurrentlyInvokedFactoryMethod(Method method)
Check whether the given method corresponds to the container's currently invoked factory method. |
| public boolean | isMatch(Method candidateMethod)
Implements org. |
| private Object | resolveBeanReference(Method beanMethod, Object[] beanMethodArgs, ConfigurableBeanFactory beanFactory, String beanName)
|
| BeanMethodInterceptor | back to summary |
|---|---|
| private BeanMethodInterceptor() | |
| createCglibProxyForFactoryBean | back to summary |
|---|---|
| private Object createCglibProxyForFactoryBean(Object factoryBean, ConfigurableBeanFactory beanFactory, String beanName) | |
| createInterfaceProxyForFactoryBean | back to summary |
|---|---|
| private Object createInterfaceProxyForFactoryBean(Object factoryBean, Class<?> interfaceType, ConfigurableBeanFactory beanFactory, String beanName) | |
| enhanceFactoryBean | back to summary |
|---|---|
| private Object enhanceFactoryBean(Object factoryBean, Class<?> exposedType, ConfigurableBeanFactory beanFactory, String beanName) Create a subclass proxy that intercepts calls to getObject(), delegating to the current BeanFactory instead of creating a new instance. These proxies are created only when calling a FactoryBean from within a Bean method, allowing for proper scoping semantics even when working against the FactoryBean instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing, it will not be proxied. This too is aligned with the way XML configuration works. | |
| factoryContainsBean | back to summary |
|---|---|
| private boolean factoryContainsBean(ConfigurableBeanFactory beanFactory, String beanName) Check the BeanFactory to see whether the bean named beanName already exists. Accounts for the fact that the requested bean may be "in creation", i.e.: we're in the middle of servicing the initial request for this bean. From an enhanced factory method's perspective, this means that the bean does not actually yet exist, and that it is now our job to create it for the first time by executing the logic in the corresponding factory method. Said another way, this check repurposes
| |
| getBeanFactory | back to summary |
|---|---|
| private ConfigurableBeanFactory getBeanFactory(Object enhancedConfigInstance) | |
| intercept | back to summary |
|---|---|
| public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs, MethodProxy cglibMethodProxy) throws Throwable Implements org. Enhance a
| |
| isCurrentlyInvokedFactoryMethod | back to summary |
|---|---|
| private boolean isCurrentlyInvokedFactoryMethod(Method method) Check whether the given method corresponds to the container's currently invoked factory method. Compares method name and parameter types only in order to work around a potential problem with covariant return types (currently only known to happen on Groovy classes). | |
| isMatch | back to summary |
|---|---|
| public boolean isMatch(Method candidateMethod) Implements org.
| |
| resolveBeanReference | back to summary |
|---|---|
| private Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs, ConfigurableBeanFactory beanFactory, String beanName) | |
Callback.
ConditionalCallbackFilter
| Modifier and Type | Method and Description |
|---|---|
| public boolean |
| isMatch | back to summary |
|---|---|
| public boolean isMatch(Method candidateMethod) | |
CallbackFilter that works by interrogating Callbacks in the order
that they are defined via ConditionalCallback.
| Modifier and Type | Field and Description |
|---|---|
| private final Callback[] | |
| private final Class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | accept(Method
the intercepted method method)Implements org. |
| public Class |
| callbacks | back to summary |
|---|---|
| private final Callback[] callbacks | |
| callbackTypes | back to summary |
|---|---|
| private final Class<?>[] callbackTypes | |
| ConditionalCallbackFilter | back to summary |
|---|---|
| public ConditionalCallbackFilter(Callback[] callbacks) | |
| accept | back to summary |
|---|---|
| public int accept(Method method) Implements org. Doc from org. Map a method to a callback.
| |
| getCallbackTypes | back to summary |
|---|---|
| public Class | |
ConfigurationClassEnhancer#enhance
through checking to see if candidate classes are already assignable to it, e.g.
have already been enhanced.
Also extends BeanFactoryAware, as all enhanced @Configuration
classes require access to the BeanFactory that created them.
Note that this interface is intended for framework-internal use only, however must remain public in order to allow access to subclasses generated from other packages (i.e. user code).