Spring Data Rest - PagedResourceAssembler异常

时间:2014-09-24 06:57:35

标签: java spring rest spring-data-rest spring-hateoas

我有以下配置文件:

<beans>
<bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <mvc:default-servlet-handler/>
    <mvc:resources mapping="/app/**" location="/WEB-INF/app/"/>

    <bean class="my.example.config.RestConfiguration"/>

    <mvc:annotation-driven/>
</bean>

我的Rest配置类

@Configuration
public class RestConfiguration extends RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
                //Nothing for now
    }
}

这是我的控制器

@RepositoryRestController
public class TransmissionController {

    @Autowired
    private TransmissionRepository transmissionRepository;

    @ResponseBody
    @RequestMapping(value = "/transmissions/search/all", method = RequestMethod.GET)
    public PagedResources<Resource<Transmission>> getAll(
            PagedResourcesAssembler<Transmission> assembler, 
            TransmissionFilterCriteria filterCriteria, Pageable pageable) {

        Specification<Transmission> specification = new TransmissionSpecification(filterCriteria);

        Page<Transmission> transmissions = transmissionRepository.findAll(specification, pageable);
        return assembler.toResource(transmissions);
    }
}

最后我正在使用的库:

 <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.6.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-webmvc</artifactId>
        <version>2.1.1.RELEASE</version>
  </dependency>

通过公开RepositoryRestMvcConfiguration,我应该完成所有配置。但是,在尝试访问资源时,我收到以下异常:

org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.web.PagedResourcesAssembler]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.data.web.PagedResourcesAssembler.<init>()
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:108)
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:136)
    at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:81)
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:101)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:685)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: java.lang.NoSuchMethodException: org.springframework.data.web.PagedResourcesAssembler.<init>()
    at java.lang.Class.getConstructor0(Class.java:2849)
    at java.lang.Class.getDeclaredConstructor(Class.java:2053)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
    ... 34 more

我已尝试使用我的Transmission实体扩展ResourceSupport但没有,但它似乎没有任何区别。

任何想法我做错了什么?

0 个答案:

没有答案