From 7eb98b44879618b675d859a30d9868484a404445 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 30 Oct 2024 16:51:13 -0700 Subject: [PATCH] Store bind handlers on first access Update `ConfigurationPropertiesBinder` so that bind handler are fetched and stored once. Closes gh-42950 --- .../ConfigurationPropertiesBinder.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java index 4ef79c8cd7..c19a071911 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java @@ -76,6 +76,8 @@ class ConfigurationPropertiesBinder { private final boolean jsr303Present; + private volatile List bindHandlerAdvisors; + private volatile Binder binder; ConfigurationPropertiesBinder(ApplicationContext applicationContext) { @@ -126,6 +128,18 @@ class ConfigurationPropertiesBinder { return handler; } + private List getBindHandlerAdvisors() { + List bindHandlerAdvisors = this.bindHandlerAdvisors; + if (bindHandlerAdvisors == null) { + bindHandlerAdvisors = this.applicationContext + .getBeanProvider(ConfigurationPropertiesBindHandlerAdvisor.class) + .orderedStream() + .toList(); + this.bindHandlerAdvisors = bindHandlerAdvisors; + } + return bindHandlerAdvisors; + } + private IgnoreTopLevelConverterNotFoundBindHandler getHandler() { BoundConfigurationProperties bound = BoundConfigurationProperties.get(this.applicationContext); return (bound != null) @@ -164,12 +178,6 @@ class ConfigurationPropertiesBinder { return new ConfigurationPropertiesJsr303Validator(this.applicationContext, type); } - private List getBindHandlerAdvisors() { - return this.applicationContext.getBeanProvider(ConfigurationPropertiesBindHandlerAdvisor.class) - .orderedStream() - .toList(); - } - private Binder getBinder() { if (this.binder == null) { this.binder = new Binder(getConfigurationPropertySources(), getPropertySourcesPlaceholdersResolver(),