[英]EnableSpringDataWebSupport doesn't seem to work well with WebMvcConfigurerAdapter
I was successfully using @EnableSpringDataWebSupport
in my Spring Boot app to enable pagination, sorting and stuff. 我在Spring Boot应用程序中成功使用
@EnableSpringDataWebSupport
来启用分页,排序和填充。 However, at some point, I had to introduce a custom argument resolver and did it with Java config as follows: 但是,在某些时候,我不得不引入一个自定义参数解析器并使用Java配置执行如下操作:
@Configuration
@EnableSpringDataWebSupport
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(renamingProcessor());
}
@Bean
protected RenamingProcessor renamingProcessor() {
return new RenamingProcessor(true);
}
}
It made my new argument resolver work, however completely broke paging and other features, that were automatically configured by @EnableSpringDataWebSupport
. 它使我的新参数解析器工作,但完全打破了分页和其他功能,这些功能由
@EnableSpringDataWebSupport
自动配置。 I've tried switching WebMvcConfigurerAdapter
to alternatives like DelegatingWebMvcConfiguration
or WebMvcConfigurationSupport
, but no luck -- pagination fails with the exception: 我已经尝试将
WebMvcConfigurerAdapter
切换到DelegatingWebMvcConfiguration
或WebMvcConfigurationSupport
类的替代品,但没有运气 - 分页失败,例外情况如下:
Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface
无法实例化[org.springframework.data.domain.Pageable]:指定的类是一个接口
I would appreciate any help or advice how to handle this issue. 我将不胜感激任何帮助或建议如何处理这个问题。 Similar questions didn't help a lot:
类似的问题没有多大帮助:
So, after some investigation, I figured out the solution (perhaps, not ideal one, but still working -- I'd still be happy to see the "right" resolution for the problem from Spring professionals). 因此,经过一些调查后,我找到了解决方案(也许,不理想的解决方案,但仍在工作 - 我仍然很高兴看到Spring专业人员解决问题的“正确”解决方案)。 What I changed is switching from
extends WebMvcConfigurerAdapter
to extends HateoasAwareSpringDataWebConfiguration
(since we're using HATEOAS). 我改变的是从
extends WebMvcConfigurerAdapter
切换到extends HateoasAwareSpringDataWebConfiguration
(因为我们正在使用HATEOAS)。 I also updated the overridden addArgumentResolvers
and now my MvcConfig
looks like this: 我还更新了重写的
addArgumentResolvers
,现在我的MvcConfig
看起来像这样:
@Configuration
public class MvcConfig extends HateoasAwareSpringDataWebConfiguration {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
super.addArgumentResolvers(argumentResolvers);
argumentResolvers.add(renamingProcessor());
}
@Bean
protected RenamingProcessor renamingProcessor() {
return new RenamingProcessor(true);
}
}
The issue with Pageable
disappeared, and custom RenamingProcessor
works like a charm. Pageable
的问题消失了,自定义RenamingProcessor
就像魅力一样。
Hope this answer will help someone who's facing similar issue. 希望这个答案可以帮助那些面临类似问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.