Spring Data Rest PagingAndSortingRepository AbstractMethodError(RepositoryFactorySupport)
我正在尝试使用Spring Data Rest构建Rest Api,在多次更改我的pom.xml以找到与我的项目兼容的依赖项之后,我现在遇到了这个问题:
java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
很久以前 …
我有一个Java Config Web App,我的JPAConfig有这些注释
@Configuration //@EnableJpaRepositories("com.protect.inf.jpa.repositories") @EnableJpaRepositories @EnableTransactionManagement public class JPAConfig { ... }
请参阅@EnableJpaRepositories
注释,如果我没有将包名称设置为我的Repositories类,则应用程序启动正常,但是当我向api发出请求时,响应如下所示:
{ _links: { profile: { href: "http://localhost:8080/protect-inf-01/api/profile" }- }- }
它没有暴露我的Reposurl。 我的Repos类看起来像这样
@RestResource(path = "users", rel = "users") public interface UsuariosRepository extends PagingAndSortingRepository{ Usuarios findByEmail(String email); }
然后 …
当我将包名称设置为@EnableRepositories
注释@EnableJpaRepositories("com.protect.inf.jpa.repositories")
,应用程序启动失败,并显示以下错误:
Error creating bean with name 'cuentasRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
我认为这是我Maven中的依赖问题,我不太确定。 这是我的pom.xm
4.0.0 protect-inf-01 protect-inf-01 war 0.0.1-SNAPSHOT protect-inf-01 Maven Webapp http://maven.apache.org 1.6.10 1.9.13 4.2.0.Final 4.1.7.RELEASE 1.6.6 spring-milestones http://repo.spring.io/libs-milestone/ org.springframework.data spring-data-rest-webmvc 2.4.0.RELEASE org.springframework spring-aop 4.2.1.RELEASE org.springframework.data spring-data-commons 1.11.0.RC1 org.springframework spring-orm 4.2.1.RELEASE org.springframework.data spring-data-jpa 1.8.2.RELEASE org.springframework spring-context 4.2.1.RELEASE mysql mysql-connector-java 5.1.6 org.hibernate hibernate-validator 4.2.0.Final org.hibernate hibernate-entitymanager 4.2.6.Final javax.servlet javax.servlet-api 3.1.0 javax.servlet.jsp jsp-api 2.2 provided javax.servlet jstl 1.2 org.slf4j slf4j-api ${org.slf4j-version} org.apache.commons commons-lang3 3.0 org.slf4j jcl-over-slf4j ${org.slf4j-version} runtime org.slf4j slf4j-log4j12 ${org.slf4j-version} runtime protect-inf-01
这是我的WebAppInitializer
类
package com.protect.inf.config; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class[] getRootConfigClasses() { return new Class[]{JPAConfig.class}; } @Override protected Class[] getServletConfigClasses() { return new Class[]{WebConfiguration.class}; } @Override protected String[] getServletMappings() { return new String[]{"/"}; } }
这是我的WebConfiguration
类
package com.protect.inf.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; @Configuration public class WebConfiguration extends RepositoryRestMvcConfiguration{ @Override public RepositoryRestConfiguration config() { RepositoryRestConfiguration config = super.config(); config.setBasePath("/api"); return config; } }
欢迎任何帮助,谢谢!
已解决删除spring-data-commons
并将spring-data-jpa
版本更改为1.9.0.RELEASE就像@peeskillet说现在工作正常!
评论spring-data-commons依赖项
<!-- --> <!-- org.springframework.data --> <!-- spring-data-commons --> <!-- 1.11.0.RC1 --> <!-- -->
更改spring-data-jpa版本
<!-- --> <!-- org.springframework.data --> <!-- spring-data-jpa --> <!-- 1.8.2.RELEASE --> <!-- --> org.springframework.data spring-data-jpa 1.9.0.RELEASE
谢谢peeskillet!
摆脱spring-data-commons
并将spring-data-jpa
版本更改为1.9.0.RELEASE
。
spring-data-rest-webmvc
和spring-data-jpa
已经依赖于spring-data-commons
。 但是你需要确保它们都依赖于相同的版本。 sd-rest-webmvc-2.4.0
依赖于sd-commons-1.11.0
而sd-jpa-1.8.2
依赖于sd-commons-1.10.2
。 这就是区别。 sd-jpa-1.9.0
取决于sd-commons-1.11.0
。