spring-mvcspring-dataspring-data-commons

Cannot pass @SortDefault Sort object into controller method?


It is stated in the documentation of @SortDefault that

Annotation to define the default Sort options to be used when injecting a Sort instance into a controller handler method.

But the fact is, I got this exception:

Failed to instantiate [org.springframework.data.domain.Sort]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.data.domain.Sort.()

Did I miss something here?

void download(WebRequest request, HttpSession session,
      @RequestParam(value = "fields",
          defaultValue = "id,hostname,networkId,customerId") String[] visibleProperties,
      @SortDefault("hostname") Sort sort, HttpServletResponse response) {
}

Solution

  • You probably missed an @EnableSpringDataWebSupport in your configuration.