升级到spring-data 1.9

时间:2015-10-10 19:54:51

标签: spring-data spring-data-jpa

将spring-data从1.8升级到1.9后,我收到以下错误:

Caused by: java.lang.IllegalStateException: No suitable constructor found on interface com.acme.util.RepositoryEx to match the given arguments: [Ljava.lang.Object;@4ef820c3
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepositoryViaReflection(RepositoryFactorySupport.java:338)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:91)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:71)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 87 more

我有一个简单的RepositoryEx类,如:

public interface RepositoryEx<T, ID extends Serializable> extends JpaRepository<T, ID>,
        JpaSpecificationExecutor<T> {

    List<T> findAll(Specification<T> spec, Sort sort, long offset, long count);


}

我的其他存储库接口都是继承的,我还需要添加其他东西吗?

谢谢,杰森

1 个答案:

答案 0 :(得分:1)

我刚遇到这个问题。我的基本存储库实现类扩展了SimpleJpaRepository,并且只有一个带有参数Class<T> domainClass, EntityManager em的构造函数。添加以下构造函数为我解决了这个问题:

public MyBaseRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
  super(entityInformation, entityManager);
}