gpt4 book ai didi

java - 无法实例化 Pageable bean

转载 作者:IT老高 更新时间:2023-10-28 13:51:44 28 4
gpt4 key购买 nike

我使用 Spring 4.1.6.RELEASE 和 Spring Data Jpa 1.8.0.RELEASE。我在创建 org.springframework.data.domain.Pageable bean 时遇到问题。它在我的 Controller 中使用:

@Controller
public class ItemsController {

@Autowired
ProductService itemsService;

@RequestMapping(value = "/openItemsPage")
public String openItemsPage() {
return "items";
}

@RequestMapping(value = "/getItems", method = RequestMethod.GET)
@ResponseBody
public Item[] getItems(Pageable pageable) {

return itemsService.getItems(pageable);
}
}

我的应用程序上下文中还有下一个 xml 配置:

<context:component-scan base-package="com.mobox.controller" />

<mvc:annotation-driven>
<mvc:argument-resolvers>
<beans:bean id="sortResolver"
class="org.springframework.data.web.SortHandlerMethodArgumentResolver" />
<beans:bean
class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
<beans:constructor-arg ref="sortResolver" />
</beans:bean>
</mvc:argument-resolvers>
</mvc:annotation-driven>

最后我从客户那里做一个下一个请求:

   $.ajax({
type: "GET",
url: "getProducts?page=0&size=100",
.....

在tomcat日志中我看到下一个:

    SEVERE: Servlet.service() for servlet [appServlet] in context with path [/a2delivery-web] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface] with root cause
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:80)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
....................

请帮我解决这个问题,谢谢!

最佳答案

最简单的方法是在你的配置中设置 @EnableSpringDataWebSupport。或者,在基于纯 XML 的配置中,将 SpringDataWebConfiguration 声明为 Spring bean。

这将确保正确注册必要的 HandlerMethodArgumentResolver

关于java - 无法实例化 Pageable bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30057262/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com