DATACMNS-822 - Provide customizers for default pageable and sort resolvers.
Introduced dedicated callback interfaces to customize the HandlerMethodArgumentResolver instances registered by SpringDataWebConfiguration. This allows bean definition registration of those customizer interfaces instead of having to extend a configuration class. Original pull request: #208.
This commit is contained in:
committed by
Oliver Gierke
parent
34ce83c657
commit
c1036b2204
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,6 +36,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
* @author Oliver Gierke
|
||||
* @author Nick Williams
|
||||
* @author Ben Hale
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
@Configuration
|
||||
public class HateoasAwareSpringDataWebConfiguration extends SpringDataWebConfiguration {
|
||||
@@ -56,7 +57,10 @@ public class HateoasAwareSpringDataWebConfiguration extends SpringDataWebConfigu
|
||||
@Bean
|
||||
@Override
|
||||
public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {
|
||||
return new HateoasPageableHandlerMethodArgumentResolver(sortResolver());
|
||||
HateoasPageableHandlerMethodArgumentResolver pageableResolver =
|
||||
new HateoasPageableHandlerMethodArgumentResolver(sortResolver());
|
||||
customizePageableResolver(pageableResolver);
|
||||
return pageableResolver;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -66,7 +70,9 @@ public class HateoasAwareSpringDataWebConfiguration extends SpringDataWebConfigu
|
||||
@Bean
|
||||
@Override
|
||||
public HateoasSortHandlerMethodArgumentResolver sortResolver() {
|
||||
return new HateoasSortHandlerMethodArgumentResolver();
|
||||
HateoasSortHandlerMethodArgumentResolver sortResolver = new HateoasSortHandlerMethodArgumentResolver();
|
||||
customizeSortResolver(sortResolver);
|
||||
return sortResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.web.config;
|
||||
|
||||
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
|
||||
|
||||
/**
|
||||
* Callback interface that can be implemented by beans wishing to customize the
|
||||
* {@link PageableHandlerMethodArgumentResolver} configuration.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public interface PageableHandlerMethodArgumentResolverCustomizer {
|
||||
|
||||
/**
|
||||
* Customize the pageable resolver
|
||||
*
|
||||
* @param pageableResolver the {@link PageableHandlerMethodArgumentResolver} to customize
|
||||
*/
|
||||
void customize(PageableHandlerMethodArgumentResolver pageableResolver);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.web.config;
|
||||
|
||||
import org.springframework.data.web.SortHandlerMethodArgumentResolver;
|
||||
|
||||
/**
|
||||
* Callback interface that can be implemented by beans wishing to customize the
|
||||
* {@link SortHandlerMethodArgumentResolver} configuration.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public interface SortHandlerMethodArgumentResolverCustomizer {
|
||||
|
||||
/**
|
||||
* Customize the sort resolver
|
||||
*
|
||||
* @param sortResolver the {@link SortHandlerMethodArgumentResolver} to customize
|
||||
*/
|
||||
void customize(SortHandlerMethodArgumentResolver sortResolver);
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @since 1.6
|
||||
* @author Oliver Gierke
|
||||
* @author Vedran Pavic
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@Configuration
|
||||
@@ -61,13 +62,22 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
private PageableHandlerMethodArgumentResolverCustomizer pageableResolverCustomizer;
|
||||
|
||||
@Autowired(required = false)
|
||||
private SortHandlerMethodArgumentResolverCustomizer sortResolverCustomizer;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.web.config.SpringDataWebConfiguration#pageableResolver()
|
||||
*/
|
||||
@Bean
|
||||
public PageableHandlerMethodArgumentResolver pageableResolver() {
|
||||
return new PageableHandlerMethodArgumentResolver(sortResolver());
|
||||
PageableHandlerMethodArgumentResolver pageableResolver =
|
||||
new PageableHandlerMethodArgumentResolver(sortResolver());
|
||||
customizePageableResolver(pageableResolver);
|
||||
return pageableResolver;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -76,7 +86,9 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
*/
|
||||
@Bean
|
||||
public SortHandlerMethodArgumentResolver sortResolver() {
|
||||
return new SortHandlerMethodArgumentResolver();
|
||||
SortHandlerMethodArgumentResolver sortResolver = new SortHandlerMethodArgumentResolver();
|
||||
customizeSortResolver(sortResolver);
|
||||
return sortResolver;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -139,4 +151,17 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
converters.add(0, new XmlBeamHttpMessageConverter());
|
||||
}
|
||||
}
|
||||
|
||||
protected void customizePageableResolver(PageableHandlerMethodArgumentResolver pageableResolver) {
|
||||
if (this.pageableResolverCustomizer != null) {
|
||||
this.pageableResolverCustomizer.customize(pageableResolver);
|
||||
}
|
||||
}
|
||||
|
||||
protected void customizeSortResolver(SortHandlerMethodArgumentResolver sortResolver) {
|
||||
if (this.sortResolverCustomizer != null) {
|
||||
this.sortResolverCustomizer.customize(sortResolver);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user