5

I was successfully using @EnableSpringDataWebSupport in my Spring Boot app to enable pagination, sorting and stuff. However, at some point, I had to introduce a custom argument resolver and did it with Java config as follows:

@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. I've tried switching WebMvcConfigurerAdapter to alternatives like DelegatingWebMvcConfiguration or WebMvcConfigurationSupport, but no luck -- pagination fails with the exception:

Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface

I would appreciate any help or advice how to handle this issue. Similar questions didn't help a lot:

Community
  • 1
  • 1
Vladimir Salin
  • 2,951
  • 2
  • 36
  • 49
  • 1
    You shouldn't need `@EnableSpringDataWebSupport` as that is already taken care of by Spring Boot when those classes are found. – M. Deinum Mar 10 '17 at 16:02
  • @m-deinum thanks for a quick response. I removed `@EnableSpringDataWebSupport` from config class, but result is the same -- pagination doesn't work – Vladimir Salin Mar 10 '17 at 16:19

1 Answers1

3

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). What I changed is switching from extends WebMvcConfigurerAdapter to extends HateoasAwareSpringDataWebConfiguration (since we're using HATEOAS). I also updated the overridden addArgumentResolvers and now my MvcConfig looks like this:

@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.

Hope this answer will help someone who's facing similar issue.

Vladimir Salin
  • 2,951
  • 2
  • 36
  • 49