I'm trying to buil an Rest Api using Spring Data Rest, after to change my pom.xml many times to find the compatible dependencies to my project, I have this problem now:
我正在尝试使用Spring数据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;
Once upon a time ...
从前……
I have a Java Config Web App, my JPAConfig has these annotations
我有一个Java配置Web应用,我的JPAConfig有这些注解
@Configuration
//@EnableJpaRepositories("com.protect.inf.jpa.repositories")
@EnableJpaRepositories
@EnableTransactionManagement
public class JPAConfig { ... }
See the @EnableJpaRepositories
annotation, if i don´t set the package name where are my Repositories class, the application starts fine, but when I make the request to the api, the response looks like this:
´看到@EnableJpaRepositories注释,如果我不设置的程序包的名称是我的类库,应用程序开始很好,但当我请求api,反应是这样的:
{
_links: {
profile: {
href: "http://localhost:8080/protect-inf-01/api/profile"
}-
}-
}
It doesn´t expose my Repos url. My Repos classes looks like this
并´t暴露我的回购url。我的Repos类是这样的
@RestResource(path = "users", rel = "users")
public interface UsuariosRepository extends PagingAndSortingRepository<Usuarios, Integer>{
Usuarios findByEmail(String email);
}
Then ...
然后……
When I set the package name to the @EnableRepositories
annotation @EnableJpaRepositories("com.protect.inf.jpa.repositories")
the applications start fails with this error:
当我将包名设置为@ enablerepository注释@ enablejparepository(“com. protect.inf.jpa.repository”)时,应用程序会以以下错误开始失败:
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;
I think that is a dependencies problem in my Maven, i'm not really sure. Here is my pom.xm
我认为这是我的专家的依赖问题,我不是很确定。这是我pom.xm
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>protect-inf-01</groupId>
<artifactId>protect-inf-01</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>protect-inf-01 Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<org.aspectj-version>1.6.10</org.aspectj-version>
<jackson.version>1.9.13</jackson.version>
<hibernate.validator.version>4.2.0.Final</hibernate.validator.version>
<org.springframework-version>4.1.7.RELEASE</org.springframework-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<repositories>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/libs-milestone/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.11.0.RC1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.6.Final</version>
</dependency>
<!-- SERVLET -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>protect-inf-01</finalName>
</build>
</project>
This is my WebAppInitializer
class
这是我的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[]{"/"};
}
}
This is my WebConfiguration
class
这是我的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;
}
}
Any help is welcome, thanks!
欢迎任何帮助,谢谢!
SOLVED Deleting the spring-data-commons
and changing the spring-data-jpa
version to 1.9.0.RELEASE like @peeskillet said now works fine!
解决了删除spring-data-commons并将spring-data-jpa版本更改为1.9.0。发布像@peeskillet说的现在很好!
Comment the spring-data-commons dependency
评论spring-data-commons依赖性
<!-- <dependency> -->
<!-- <groupId>org.springframework.data</groupId> -->
<!-- <artifactId>spring-data-commons</artifactId> -->
<!-- <version>1.11.0.RC1</version> -->
<!-- </dependency> -->
Change the spring-data-jpa version
改变spring-data-jpa版本
<!-- <dependency> -->
<!-- <groupId>org.springframework.data</groupId> -->
<!-- <artifactId>spring-data-jpa</artifactId> -->
<!-- <version>1.8.2.RELEASE</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>
Thanks peeskillet!
谢谢peeskillet !
1 个解决方案
#1
13
Get rid of spring-data-commons
and change spring-data-jpa
version to 1.9.0.RELEASE
.
摆脱spring-data-commons并将spring-data-jpa版本更改为1.9.0.RELEASE。
Both spring-data-rest-webmvc
and spring-data-jpa
already depend on spring-data-commons
. But you need to make sure that they both depend on the same version. s-d-rest-webmvc-2.4.0
depends on s-d-commons-1.11.0
while s-d-jpa-1.8.2
depends on s-d-commons-1.10.2
. And that's the difference. s-d-jpa-1.9.0
depends on s-d-commons-1.11.0
.
spring-data-res -webmvc和spring-data-jpa都已经依赖于spring-data-commons。但是您需要确保它们都依赖于相同的版本。s-d-rest-webmvc-2.4.0依赖于s-d-common -1.11.0,而s-d-jpa-1.8.2依赖于s-d-common -1.10.2。这就是区别。s-d-jpa-1.9.0取决于s-d-commons-1.11.0。
#1
13
Get rid of spring-data-commons
and change spring-data-jpa
version to 1.9.0.RELEASE
.
摆脱spring-data-commons并将spring-data-jpa版本更改为1.9.0.RELEASE。
Both spring-data-rest-webmvc
and spring-data-jpa
already depend on spring-data-commons
. But you need to make sure that they both depend on the same version. s-d-rest-webmvc-2.4.0
depends on s-d-commons-1.11.0
while s-d-jpa-1.8.2
depends on s-d-commons-1.10.2
. And that's the difference. s-d-jpa-1.9.0
depends on s-d-commons-1.11.0
.
spring-data-res -webmvc和spring-data-jpa都已经依赖于spring-data-commons。但是您需要确保它们都依赖于相同的版本。s-d-rest-webmvc-2.4.0依赖于s-d-common -1.11.0,而s-d-jpa-1.8.2依赖于s-d-common -1.10.2。这就是区别。s-d-jpa-1.9.0取决于s-d-commons-1.11.0。