我是春季数据的新手,我正在尝试自定义它。这是我到目前为止尝试的:我的基本存储库接口
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.
不完全确定这是对以后帮助人们的答案,但解决了我的问题,只是在每种服务中添加了以下方法:
@Bean
@Override
public Class<User> getDomain() {
return User.class;
}