[英]When loading a spring context, the repository bean is not created
我正在尝试创建存储库但出现错误。
我的接口存储库:
public interface CallRepository extends JpaRepository<Call, Integer> {
@Override
@Transactional
Call save(Call call);
@Modifying
@Transactional
@Query("DELETE FROM Call c WHERE c.id=:id AND c.subscriber.id=:subscriberId")
int delete(@Param("id") int id, @Param("subscriberId") int subscriberId);
@Query("SELECT Call FROM Call c WHERE c.subscriber.id=:subscriberId")
List<Call> getAll(@Param("subscriberId") int subscriberId);
List<Call> getAllBySubscriberIdAndDateTimeBetween(int subscriberId, LocalDateTime startDateTime, LocalDateTime endDateTime);
}
我的存储库 class:
@Repository
public class CallRepositoryImpl {
@Autowired
private SubscriberRepository subscriberRepository;
@Autowired
private CallRepository repository;
@Transactional
public Call save(Call call, int subscriberId) {
if (!call.isNew() && get(call.getId(), subscriberId) == null) {
return null;
}
call.setSubscriber(subscriberRepository.getOne(subscriberId));
return repository.save(call);
}
public Call get(int id, int subscriberId) {
return repository.findById(id)
.filter(t -> t.getSubscriber().getId() == subscriberId)
.orElse(null);
}
public boolean delete(int id, int subscriberId) {
return repository.delete(id, subscriberId) != 0;
}
public List<Call> getAll(int subscriberId) {
return repository.getAll(subscriberId);
}
public List<Call> getBetweenDateTime(int subscriberId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
Objects.requireNonNull(startDateTime, "startDateTime must not be null");
Objects.requireNonNull(endDateTime, "endDateTime must not be null");
return repository.getAllBySubscriberIdAndDateTimeBetween(subscriberId, startDateTime, endDateTime);
}
}
加载 spring 上下文时,出现错误:
创建名称为“callRepositoryImpl”的 bean 时出错:通过字段“repository”表示的依赖关系不满足; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“callRepository”的 bean 时出错:调用 init 方法失败; 嵌套异常是 java.lang.IllegalArgumentException:验证方法公共抽象 java.util.List ru.subscribers.repository.events.CallRepository.getAll(int) 查询失败!
在类型为 Integer 的数据库“id”中,也在类型为 Integer 的实体“id”中。
告诉我可能是什么问题?
我不确定,但不应该这样查询吗?
@Query("SELECT c FROM Call c WHERE c.subscriber.id=:subscriberId")
你能告诉我你的上下文文件吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.