Skip to content

Commit 7eb98b4

Browse files
committed
Store bind handlers on first access
Update `ConfigurationPropertiesBinder` so that bind handler are fetched and stored once. Closes gh-42950
1 parent f4c6aab commit 7eb98b4

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class ConfigurationPropertiesBinder {
7676

7777
private final boolean jsr303Present;
7878

79+
private volatile List<ConfigurationPropertiesBindHandlerAdvisor> bindHandlerAdvisors;
80+
7981
private volatile Binder binder;
8082

8183
ConfigurationPropertiesBinder(ApplicationContext applicationContext) {
@@ -126,6 +128,18 @@ private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperti
126128
return handler;
127129
}
128130

131+
private List<ConfigurationPropertiesBindHandlerAdvisor> getBindHandlerAdvisors() {
132+
List<ConfigurationPropertiesBindHandlerAdvisor> bindHandlerAdvisors = this.bindHandlerAdvisors;
133+
if (bindHandlerAdvisors == null) {
134+
bindHandlerAdvisors = this.applicationContext
135+
.getBeanProvider(ConfigurationPropertiesBindHandlerAdvisor.class)
136+
.orderedStream()
137+
.toList();
138+
this.bindHandlerAdvisors = bindHandlerAdvisors;
139+
}
140+
return bindHandlerAdvisors;
141+
}
142+
129143
private IgnoreTopLevelConverterNotFoundBindHandler getHandler() {
130144
BoundConfigurationProperties bound = BoundConfigurationProperties.get(this.applicationContext);
131145
return (bound != null)
@@ -164,12 +178,6 @@ private Validator getJsr303Validator(Class<?> type) {
164178
return new ConfigurationPropertiesJsr303Validator(this.applicationContext, type);
165179
}
166180

167-
private List<ConfigurationPropertiesBindHandlerAdvisor> getBindHandlerAdvisors() {
168-
return this.applicationContext.getBeanProvider(ConfigurationPropertiesBindHandlerAdvisor.class)
169-
.orderedStream()
170-
.toList();
171-
}
172-
173181
private Binder getBinder() {
174182
if (this.binder == null) {
175183
this.binder = new Binder(getConfigurationPropertySources(), getPropertySourcesPlaceholdersResolver(),

0 commit comments

Comments
 (0)