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;
}
Run Code Online (Sandbox Code Playgroud)
}
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();
}
Run Code Online (Sandbox Code Playgroud)
在我的配置类中,我有 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]。确保你实现了一个带有这些的构造函数
小智 5
我刚才遇到了同样的问题,经过一些调试后,我找到了解决方案:
确保您只有一个EnableJpaRepositories注释并且它指向实现类(而不是接口):
@EnableJpaRepositories(repositoryBaseClass = GenericJpaRepositoryImpl.class)
我希望它可以帮助将来的某个人;)
| 归档时间: |
|
| 查看次数: |
1797 次 |
| 最近记录: |