【发布时间】:2017-04-15 01:14:25
【问题描述】:
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.QueryDslJpaRepository;
import org.springframework.data.querydsl.EntityPathResolver;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
@NoRepositoryBean
public class RepositorySupportImpl<T> extends QueryDslJpaRepository<T, Integer> implements RepositorySupport<T> {
private EntityManager entityManager;
public RepositorySupportImpl(JpaEntityInformation<T, Integer> entityInformation, EntityManager entityManager, EntityManager entityManager1) {
super(entityInformation, entityManager);
this.entityManager = entityManager1;
}
public RepositorySupportImpl(JpaEntityInformation<T, Integer> entityInformation, EntityManager entityManager, EntityPathResolver resolver, EntityManager entityManager1) {
super(entityInformation, entityManager, resolver);
this.entityManager = entityManager1;
}
@Override
public EntityManager getEntityManager() {
return this.entityManager;
}
@Transactional
@Override
public <S extends T> S save(final S entity) {
this.getEntityManager().persist(entity);
return entity;
}
}
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import javax.persistence.EntityManager;
public interface RepositorySupport<T> extends JpaRepository<T, Integer>, QueryDslPredicateExecutor<T> {
EntityManager getEntityManager();
}
在我的配置类中,我有 repositoryBaseClass = RepositorySupportImpl.class
但我收到此错误:
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“registerService”的bean时出错:通过字段“userRepository”表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“userRepository”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IllegalStateException:在类 ca.lighthouse.repository.RepositorySupportImpl 上找不到合适的构造函数来匹配给定的参数:[class org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation, class com.sun.proxy .$Proxy52]。确保你实现了一个构造函数来接受这些
【问题讨论】:
-
您是否尝试在它要求的 RepositorySupportImpl 中添加所需的构造函数?
-
是的,我让 ide 生成构造函数,但它不会创建这个构造函数,而且我不确定“com.sun.proxy.$Proxy52”的预期。
-
我认为根据该页面 javacodegeeks.com/2012/08/… 您可能缺少 Class> springDataRepositoryInterface。试着按照他们在那里的做法告诉我们。
-
我在stackoverflow.com/questions/53638214/…遇到了同样的问题
标签: spring-mvc