我是初学数据的新手,我正在尝试自定义它。这是我到目前为止所尝试的: 我的基础存储库接口
public interface IBaseRepository<T extends BaseEntity<PK>, PK extends Serializable> extends JpaRepository<T, PK> {
}
它的实施
public class BaseRepository<T extends BaseEntity<PK>, PK extends Serializable> extends SimpleJpaRepository<T, PK>
implements IBaseRepository<T, PK> {
public BaseRepository(Class<T> domainClass, EntityManager em) {
super(domainClass, em);
}
}
现在我希望为用户提供独立的存储库类
public interface IUserRepository extends IBaseRepository<User, Long> {
}
和
@Repository
public class UserRepository extends BaseRepository<User, Long> implements IUserRepository {
UserRepository(Class<User> domainClass, EntityManager em) {
super(domainClass, em);
}
}
但我得到了这个例外:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.bia2hd.dao.impl.UserRepository required a bean of type 'java.lang.Class' that could not be found.
Action:
Consider defining a bean of type 'java.lang.Class' in your configuration.
答案 0 :(得分:-1)
不完全确定这是帮助人们解决问题的答案,只是在每项服务中添加了以下方法:
@Bean
@Override
public Class<User> getDomain() {
return User.class;
}