我在http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web阅读了文档,据我所知,这是我应该如何在我的xml配置中启用Web支持:
<bean class="org.springframework.data.web.config.SpringDataWebConfiguration" />
如果我这样做,我将继续收到以下错误:
java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.project.User]: no matching editors or conversion strategy found
我试图从文档中的示例中获取来自网址的ID。
我使用Spring 4.1.7.RELEASE
以及Spring Data
的以下依赖项:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
非常感谢任何帮助。
答案 0 :(得分:3)
我认为你也需要DomainClassConverter:
<bean class="org.springframework.data.repository.support.DomainClassConverter">
<constructor-arg ref="conversionService"/>
</bean>
您可能还需要:
<bean
class="org.springframework.format.support.FormattingConversionServiceFactoryBean"
id="conversionService"
/>
当你正在设置分页和排序时:
<mvc:annotation-driven conversion-service="conversionService">
<mvc:argument-resolvers>
<bean class="org.springframework.data.web.SortHandlerMethodArgumentResolver" id="sortResolver"/>
<bean class="org.springframework.data.web.PageableHandlerMethodArgumentResolver" id="pagingResolver">
<constructor-arg ref="sortResolver"/>
</bean>
</mvc:argument-resolvers>
</mvc:annotation-driven>
答案 1 :(得分:0)
您也可以使用SpringDataWebConfiguration
中的现有配置,如下所示:
<bean id="mvcConversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>
<bean class="org.springframework.data.web.config.SpringDataWebConfiguration">
<constructor-arg ref="mvcConversionService"/>
</bean>
<bean class="org.springframework.data.web.config.QuerydslWebConfiguration"/>
<mvc:annotation-driven conversion-service="mvcConversionService">
<mvc:argument-resolvers>
<ref bean="sortResolver"/>
<ref bean="pageableResolver"/>
<ref bean="querydslPredicateArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>