gpt4 book ai didi

java - 加载 spring 上下文时,未创建存储库 bean

转载 作者:行者123 更新时间:2023-12-01 22:07:40 26 4
gpt4 key购买 nike

我正在尝试创建存储库,但出现错误。

我的界面存储库:

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);

}

我的存储库类:

@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 上下文时,出现错误:

Error creating bean with name 'callRepositoryImpl': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'callRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List ru.subscribers.repository.events.CallRepository.getAll(int)!

在数据库“id”中,类型为 Integer,在实体“id”中,类型也为 Integer。

告诉我可能是什么问题?

最佳答案

我不确定,但查询不应该是这样的吗?

@Query("SELECT c FROM Call c WHERE  c.subscriber.id=:subscriberId")

关于java - 加载 spring 上下文时,未创建存储库 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58679516/

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