diff --git a/src/main/java/org/springframework/data/convert/CustomConversions.java b/src/main/java/org/springframework/data/convert/CustomConversions.java index dec8ca27d..b326fc4ea 100644 --- a/src/main/java/org/springframework/data/convert/CustomConversions.java +++ b/src/main/java/org/springframework/data/convert/CustomConversions.java @@ -947,7 +947,7 @@ public class CustomConversions { public ConverterConfiguration(StoreConversions storeConversions, List userConverters, Predicate converterRegistrationFilter) { - this(storeConversions, userConverters, converterRegistrationFilter, new SimplePropertyValueConversions()); + this(storeConversions, userConverters, converterRegistrationFilter, PropertyValueConversions.simple(it -> {})); } /** diff --git a/src/main/java/org/springframework/data/convert/PropertyValueConversions.java b/src/main/java/org/springframework/data/convert/PropertyValueConversions.java index 1b80e96e3..981081781 100644 --- a/src/main/java/org/springframework/data/convert/PropertyValueConversions.java +++ b/src/main/java/org/springframework/data/convert/PropertyValueConversions.java @@ -63,6 +63,11 @@ public interface PropertyValueConversions { PropertyValueConverterRegistrar registrar = new PropertyValueConverterRegistrar(); config.accept(registrar); conversions.setValueConverterRegistry(registrar.buildRegistry()); + try { + conversions.afterPropertiesSet(); + } catch (Exception e) { + throw new IllegalStateException("Could not initialize value conversions."); + } return conversions; } } diff --git a/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java b/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java index 50274005b..4cc3435ad 100644 --- a/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java +++ b/src/main/java/org/springframework/data/convert/SimplePropertyValueConversions.java @@ -17,7 +17,6 @@ package org.springframework.data.convert; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import org.springframework.beans.factory.InitializingBean; import org.springframework.data.convert.PropertyValueConverterFactories.ChainedPropertyValueConverterFactory; @@ -40,7 +39,6 @@ public class SimplePropertyValueConversions implements PropertyValueConversions, private @Nullable PropertyValueConverterFactory converterFactory; private @Nullable ValueConverterRegistry valueConverterRegistry; private boolean converterCacheEnabled = true; - private final AtomicBoolean initialized = new AtomicBoolean(false); /** * Set the {@link PropertyValueConverterFactory factory} responsible for creating the actual @@ -91,11 +89,6 @@ public class SimplePropertyValueConversions implements PropertyValueConversions, @Override public boolean hasValueConverter(PersistentProperty property) { - - if (!initialized.get()) { - init(); - } - return this.converterFactory.getConverter(property) != null; } @@ -103,11 +96,6 @@ public class SimplePropertyValueConversions implements PropertyValueConversions, @Override public , D extends ValueConversionContext> PropertyValueConverter getValueConverter( C property) { - - if (!initialized.get()) { - init(); - } - return this.converterFactory.getConverter(property); } @@ -116,27 +104,24 @@ public class SimplePropertyValueConversions implements PropertyValueConversions, */ public void init() { - if (initialized.compareAndSet(false, true)) { - - List factoryList = new ArrayList<>(3); + List factoryList = new ArrayList<>(3); - if (converterFactory != null) { - factoryList.add(converterFactory); - } else { - factoryList.add(PropertyValueConverterFactory.simple()); - } + if (converterFactory != null) { + factoryList.add(converterFactory); + } else { + factoryList.add(PropertyValueConverterFactory.simple()); + } - if ((valueConverterRegistry != null) && !valueConverterRegistry.isEmpty()) { - factoryList.add(PropertyValueConverterFactory.configuredInstance(valueConverterRegistry)); - } + if ((valueConverterRegistry != null) && !valueConverterRegistry.isEmpty()) { + factoryList.add(PropertyValueConverterFactory.configuredInstance(valueConverterRegistry)); + } - PropertyValueConverterFactory targetFactory = factoryList.size() > 1 - ? PropertyValueConverterFactory.chained(factoryList) - : factoryList.iterator().next(); + PropertyValueConverterFactory targetFactory = factoryList.size() > 1 + ? PropertyValueConverterFactory.chained(factoryList) + : factoryList.iterator().next(); - this.converterFactory = converterCacheEnabled ? PropertyValueConverterFactory.caching(targetFactory) - : targetFactory; - } + this.converterFactory = converterCacheEnabled ? PropertyValueConverterFactory.caching(targetFactory) + : targetFactory; } @Override