DATACMNS-1743 - Fix lazy repository lookups in DomainClassConverter.
We now eagerly register DomainClassConverter as converter with the ConversionService in the web setup. We also refrain from explicitly registering the traget converters with the ConversionService as that might trigger a ConcurrentModificationException if called during an iteration over the converters in the first place. As DomainClassConverter registers itself for all ConvertiblePairs and delegates to the individual converters anyway.
This commit is contained in:
@@ -36,6 +36,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.core.support.DummyRepositoryFactoryBean;
|
||||
@@ -192,6 +193,16 @@ class DomainClassConverterUnitTests {
|
||||
assertThat(toIdConverter).map(it -> it.matches(SUB_USER_TYPE, target)).hasValue(false);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1743
|
||||
void registersConvertersOnConversionService() {
|
||||
|
||||
ConfigurableConversionService conversionService = new DefaultConversionService();
|
||||
DomainClassConverter<?> converter = new DomainClassConverter<>(conversionService);
|
||||
converter.setApplicationContext(initContextWithRepo());
|
||||
|
||||
assertThat(conversionService.canConvert(String.class, User.class)).isTrue();
|
||||
}
|
||||
|
||||
private ApplicationContext initContextWithRepo() {
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DummyRepositoryFactoryBean.class);
|
||||
|
||||
Reference in New Issue
Block a user