Dedicated customization callback for AuditableBeanWrapperFactory.
Introduced RepositoryRestConfigurer.customizeAuditableBeanWrapperFactory(…) so that implementations can customize the default instance provided by RepositoryRestMvcConfiguration. Fixes #2040.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.data.auditing.AuditableBeanWrapperFactory;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
@@ -132,4 +133,15 @@ public interface RepositoryRestConfigurer {
|
||||
* @param objectMapper The {@literal ObjectMapper} to be used by the system.
|
||||
*/
|
||||
default void configureJacksonObjectMapper(ObjectMapper objectMapper) {}
|
||||
|
||||
/**
|
||||
* Customize the {@link AuditableBeanWrapperFactory} to be used.
|
||||
*
|
||||
* @param factory will never be {@literal null}.
|
||||
* @return must not be {@literal null}.
|
||||
* @since 3.5
|
||||
*/
|
||||
default AuditableBeanWrapperFactory customizeAuditableBeanWrapperFactory(AuditableBeanWrapperFactory factory) {
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.rest.webmvc.config;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.data.auditing.AuditableBeanWrapperFactory;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
@@ -121,4 +122,18 @@ class RepositoryRestConfigurerDelegate implements RepositoryRestConfigurer {
|
||||
configurer.configureValidatingRepositoryEventListener(validatingListener);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer#configureAuditableBeanWrapperFactory(org.springframework.data.auditing.AuditableBeanWrapperFactory)
|
||||
*/
|
||||
@Override
|
||||
public AuditableBeanWrapperFactory customizeAuditableBeanWrapperFactory(AuditableBeanWrapperFactory factory) {
|
||||
|
||||
for (RepositoryRestConfigurer configurer : delegates) {
|
||||
factory = configurer.customizeAuditableBeanWrapperFactory(factory);
|
||||
}
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
ObjectProvider<RepresentationModelProcessorInvoker> invoker;
|
||||
ObjectProvider<MessageResolver> resolver;
|
||||
ObjectProvider<GeoModule> geoModule;
|
||||
ObjectProvider<AuditableBeanWrapperFactory> auditingBeanWrapperFactoryProvider;
|
||||
|
||||
ConversionService defaultConversionService;
|
||||
|
||||
@@ -855,7 +856,10 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
|
||||
@Bean
|
||||
public AuditableBeanWrapperFactory auditableBeanWrapperFactory(PersistentEntities persistentEntities) {
|
||||
return new MappingAuditableBeanWrapperFactory(persistentEntities);
|
||||
|
||||
AuditableBeanWrapperFactory factory = new MappingAuditableBeanWrapperFactory(persistentEntities);
|
||||
|
||||
return configurerDelegate.get().customizeAuditableBeanWrapperFactory(factory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user