Skip to content

Commit

Permalink
Store bind handlers on first access
Browse files Browse the repository at this point in the history
Update `ConfigurationPropertiesBinder` so that bind handler are fetched
and stored once.

Closes gh-42950
  • Loading branch information
philwebb committed Oct 31, 2024
1 parent f4c6aab commit 7eb98b4
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class ConfigurationPropertiesBinder {

private final boolean jsr303Present;

private volatile List<ConfigurationPropertiesBindHandlerAdvisor> bindHandlerAdvisors;

private volatile Binder binder;

ConfigurationPropertiesBinder(ApplicationContext applicationContext) {
Expand Down Expand Up @@ -126,6 +128,18 @@ private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperti
return handler;
}

private List<ConfigurationPropertiesBindHandlerAdvisor> getBindHandlerAdvisors() {
List<ConfigurationPropertiesBindHandlerAdvisor> 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)
Expand Down Expand Up @@ -164,12 +178,6 @@ private Validator getJsr303Validator(Class<?> type) {
return new ConfigurationPropertiesJsr303Validator(this.applicationContext, type);
}

private List<ConfigurationPropertiesBindHandlerAdvisor> getBindHandlerAdvisors() {
return this.applicationContext.getBeanProvider(ConfigurationPropertiesBindHandlerAdvisor.class)
.orderedStream()
.toList();
}

private Binder getBinder() {
if (this.binder == null) {
this.binder = new Binder(getConfigurationPropertySources(), getPropertySourcesPlaceholdersResolver(),
Expand Down

0 comments on commit 7eb98b4

Please sign in to comment.