See gh-31247
pull/31277/head
Stephane Nicoll 2 years ago
parent 869bb91c80
commit 8413002bcb

@ -93,8 +93,7 @@ final class ConfigurationPropertiesBeanRegistrar {
RootBeanDefinition definition = new RootBeanDefinition(type); RootBeanDefinition definition = new RootBeanDefinition(type);
definition.setAttribute(BindMethod.class.getName(), bindMethod); definition.setAttribute(BindMethod.class.getName(), bindMethod);
if (bindMethod == BindMethod.VALUE_OBJECT) { if (bindMethod == BindMethod.VALUE_OBJECT) {
definition.setInstanceSupplier( definition.setInstanceSupplier(() -> ConstructorBound.from(this.beanFactory, beanName, type));
() -> ConstructorBindingValueSupplier.createValueObject(this.beanFactory, beanName, type));
} }
return definition; return definition;
} }

@ -37,7 +37,7 @@ import org.springframework.javapoet.CodeBlock;
* {@link BeanRegistrationAotProcessor} for immutable configuration properties. * {@link BeanRegistrationAotProcessor} for immutable configuration properties.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @see ConstructorBindingValueSupplier * @see ConstructorBound
*/ */
class ConfigurationPropertiesBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { class ConfigurationPropertiesBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
@ -83,8 +83,8 @@ class ConfigurationPropertiesBeanRegistrationAotProcessor implements BeanRegistr
builder.addStatement("$T beanFactory = registeredBean.getBeanFactory()", BeanFactory.class); builder.addStatement("$T beanFactory = registeredBean.getBeanFactory()", BeanFactory.class);
builder.addStatement("$T beanName = registeredBean.getBeanName()", String.class); builder.addStatement("$T beanName = registeredBean.getBeanName()", String.class);
builder.addStatement("$T<?> beanClass = registeredBean.getBeanClass()", Class.class); builder.addStatement("$T<?> beanClass = registeredBean.getBeanClass()", Class.class);
builder.addStatement("return ($T) $T.createValueObject(beanFactory, beanName, beanClass)", builder.addStatement("return ($T) $T.from(beanFactory, beanName, beanClass)", beanClass,
beanClass, ConstructorBindingValueSupplier.class); ConstructorBound.class);
}); });
return CodeBlock.of("$T.of($T::$L)", InstanceSupplier.class, beanRegistrationCode.getClassName(), return CodeBlock.of("$T.of($T::$L)", InstanceSupplier.class, beanRegistrationCode.getClassName(),
method.getName()); method.getName());

@ -23,20 +23,20 @@ import org.springframework.beans.factory.BeanFactory;
* injection. * injection.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 6.0 * @since 3.0
* @see ConstructorBinding * @see ConstructorBinding
*/ */
public abstract class ConstructorBindingValueSupplier { public abstract class ConstructorBound {
/** /**
* Return an immutable {@link ConfigurationProperties} instance for the specified * Create an immutable {@link ConfigurationProperties} instance for the specified
* {@code beanType}. * {@code beanName} and {@code beanType} using the specified {@link BeanFactory}.
* @param beanFactory the bean factory to use * @param beanFactory the bean factory to use
* @param beanName the name of the bean * @param beanName the name of the bean
* @param beanType the type of the bean * @param beanType the type of the bean
* @return a new instance * @return an instance from the specified bean
*/ */
public static Object createValueObject(BeanFactory beanFactory, String beanName, Class<?> beanType) { public static Object from(BeanFactory beanFactory, String beanName, Class<?> beanType) {
ConfigurationPropertiesBean bean = ConfigurationPropertiesBean.forValueObject(beanType, beanName); ConfigurationPropertiesBean bean = ConfigurationPropertiesBean.forValueObject(beanType, beanName);
ConfigurationPropertiesBinder binder = ConfigurationPropertiesBinder.get(beanFactory); ConfigurationPropertiesBinder binder = ConfigurationPropertiesBinder.get(beanFactory);
try { try {
Loading…
Cancel
Save