无法实例化bean类[com.github.dandelion.datatables.core.ajax.DatatablesCriterias]:找不到默认构造函数

时间:2015-10-02 09:16:32

标签: spring spring-mvc servlet-3.0 dandelion

你知道我为什么会收到这个错误吗?

SEVERE: Servlet.service() for servlet [enemr] in context with path [/enemr] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.github.dandelion.datatables.core.ajax.DatatablesCriterias]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.github.dandelion.datatables.core.ajax.DatatablesCriterias.<init>()] with root cause
java.lang.NoSuchMethodException: com.github.dandelion.datatables.core.ajax.DatatablesCriterias.<init>()

我从这个

改变了我的控制器
@RequestMapping(value = "/results", method = RequestMethod.GET)
    public @ResponseBody DatatablesResponse<Results> findAllForDataTables(HttpServletRequest request) {

        DatatablesCriterias dataTableCriterias = DatatablesCriterias.getFromRequest(request);
        DataSet<Results> results = this.resultsServiceimpl.findResultsWithDatatablesCriterias(dataTableCriterias);
        return DatatablesResponse.build(results, dataTableCriterias);
    }

到此:

@RequestMapping(value = "/results", method = RequestMethod.GET)
    public @ResponseBody 
    DatatablesResponse<Results> findAllForDataTables(@DatatablesParams DatatablesCriterias criterias) {

        DataSet<Results> results = this.resultsServiceimpl.findResultsWithDatatablesCriterias(criterias);
        return DatatablesResponse.build(results, criterias);
    }

并突然停止工作

任何帮助高度赞赏。

我使用的是spring 3.2和蒲公英数据表1.1.0

1 个答案:

答案 0 :(得分:1)

当您将控制器更改为使用DatatablesParams注释时,您需要启用将实例化DatatablesCriterias对象的解析程序。由于正在使用spring 3.2,因此需要启用DatatablesCriteriasMethodArgumentResolver

通过xml:

     <!-- Add support for @DatatablesParams annotations in controller's methods -->
   <mvc:annotation-driven>
      <mvc:argument-resolvers>
         <bean class="com.github.dandelion.datatables.extras.spring3.ajax.DatatablesCriteriasMethodArgumentResolver" />
      </mvc:argument-resolvers>
   </mvc:annotation-driven>

或java config:

   @Configuration
   @EnableWebMvc
   public class MyWebConfig extends WebMvcConfigurerAdapter {
      @Override
      public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
         argumentResolvers.add(new DatatablesCriteriasMethodArgumentResolver());
      }
   }