我尝试加载上下文,但得到 UnsatisfiedDependencyException 我无法理解原因是什么,提供了服务中的注释和构造函数DataJpa存储库:@Transactional(readOnly = true)public interface DataJpaRepository extends JpaRepository<Visit, Long> { @Override @Transactional Visit save(Visit visit); Visit findByGuestId(long guestId); @Query("SELECT DISTINCT v FROM Visit v WHERE v.date BETWEEN :from AND :to") List<Visit> getBetween(@Param("from") Date from, @Param("to") Date to);}@Repositorypublic class VisitRepositoryImpl implements VisitRepository { @Autowired private DataJpaRepository dataJpaRepository; @Override public Visit get(long guestId) { return dataJpaRepository.findByGuestId(guestId); } @Override public Visit save(Visit visit) { return dataJpaRepository.save(visit); } @Override public List<Visit> getAll() { return dataJpaRepository.findAll(); } @Override public List<Visit> getBetween(Date from, Date to) { Objects.requireNonNull(from, "fromDate must not be null"); Objects.requireNonNull(to, "toDate must not be null"); return dataJpaRepository.getBetween(from, to); }}参观服务:@Servicepublic class VisitService { private VisitRepositoryImpl repository; @Autowired public VisitService(VisitRepositoryImpl repository) { this.repository = repository; } public Visit save(Visit visit) { return repository.save(visit); } public List<Visit> getAll() { return repository.getAll(); } public List<Visit> getBetween(Date from, Date to) { Assert.notNull(from, "fromDate must not be null"); Assert.notNull(to, "toDate must not be null"); return repository.getBetween(from, to); }}
添加回答
举报
0/150
提交
取消