Add AOT support for TypedStringValue

This commit adds support for TypeStringValue when generating AOT code.
If the value does not specify an explicit type, it's specified as is.
Otherwise, the TypeStringValue instance is restored via the appropriate
code generation.

Closes gh-29074
This commit is contained in:
Stephane Nicoll
2023-09-12 15:43:30 +02:00
committed by Stéphane Nicoll
parent 15c19411f6
commit 37c2619fc4
8 changed files with 197 additions and 4 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -311,8 +312,9 @@ final class PostProcessorRegistrationDelegate {
/**
* Selectively invoke {@link MergedBeanDefinitionPostProcessor} instances
* registered in the specified bean factory, resolving bean definitions as
* well as any inner bean definitions that they may contain.
* registered in the specified bean factory, resolving bean definitions and
* any attributes if necessary as well as any inner bean definitions that
* they may contain.
* @param beanFactory the bean factory to use
*/
static void invokeMergedBeanDefinitionPostProcessors(DefaultListableBeanFactory beanFactory) {
@@ -483,6 +485,9 @@ final class PostProcessorRegistrationDelegate {
resolveInnerBeanDefinition(valueResolver, innerBd, (innerBeanName, innerBeanDefinition)
-> postProcessRootBeanDefinition(postProcessors, innerBeanName, innerBeanType, innerBeanDefinition));
}
if (value instanceof TypedStringValue typedStringValue) {
resolveTypeStringValue(typedStringValue);
}
}
for (ValueHolder valueHolder : bd.getConstructorArgumentValues().getIndexedArgumentValues().values()) {
Object value = valueHolder.getValue();
@@ -491,6 +496,9 @@ final class PostProcessorRegistrationDelegate {
resolveInnerBeanDefinition(valueResolver, innerBd, (innerBeanName, innerBeanDefinition)
-> postProcessRootBeanDefinition(postProcessors, innerBeanName, innerBeanType, innerBeanDefinition));
}
if (value instanceof TypedStringValue typedStringValue) {
resolveTypeStringValue(typedStringValue);
}
}
}
@@ -503,6 +511,15 @@ final class PostProcessorRegistrationDelegate {
});
}
private void resolveTypeStringValue(TypedStringValue typedStringValue) {
try {
typedStringValue.resolveTargetType(this.beanFactory.getBeanClassLoader());
}
catch (ClassNotFoundException ex) {
// ignore
}
}
private Class<?> resolveBeanType(AbstractBeanDefinition bd) {
if (!bd.hasBeanClass()) {
try {