gpt4 book ai didi

spring-mvc - 创建基本存储库类时出错

转载 作者:行者123 更新时间:2023-12-02 03:57:14 24 4
gpt4 key购买 nike

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]。确保您实现了一个采用这些的构造函数

最佳答案

我刚才遇到了同样的问题,经过一些调试后我找到了解决方案:

确保您只有一个 EnableJpaRepositories 注释,并且它指向实现类(而不是接口(interface)):

@EnableJpaRepositories(repositoryBaseClass = GenericJpaRepositoryImpl.class)

我希望它对将来的人有所帮助;)

关于spring-mvc - 创建基本存储库类时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43421153/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com