org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consultaController': Unsatisfied dependency expressed through field 'agenda': Error creating bean with name 'agendaDeConsultas': Unsatisfied dependency expressed through field 'medicoRepository': Error creating bean with name 'medicoRepository' defined in med.voll.api.domain.medico.MedicoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract java.lang.Boolean med.voll.api.domain.medico.MedicoRepository.findAtivoById(java.lang.Long); Reason: Validation failed for query for method public abstract java.lang.Boolean med.voll.api.domain.medico.MedicoRepository.findAtivoById(java.lang.Long)
ConsultaController
package med.voll.api.controller;
import jakarta.validation.Valid;
import med.voll.api.domain.consulta.AgendaDeConsultas;
import med.voll.api.domain.consulta.DadosDetalhamentoConsulta;
import med.voll.api.domain.consulta.DadosAgendamentoConsulta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("consultas")
public class ConsultaController {
@Autowired
private AgendaDeConsultas agenda;
@PostMapping
@Transactional
public ResponseEntity agendar(@RequestBody @Valid DadosAgendamentoConsulta dados) {
agenda.agendar(dados);
return ResponseEntity.ok(new DadosDetalhamentoConsulta(dados));
}
}
Medico Repository
package med.voll.api.domain.medico;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;
public interface MedicoRepository extends JpaRepository<Medico, Long> {
Page<Medico> findAllByAtivoTrue(Pageable paginacao);
@Query(" " +
"select m form Medico m" +
" where m.ativo = 1 and m.especialidade = :especialidade" +
"and m.id not in(" +
" select cm.medico.id from Consulta c where c.data = :data)" +
" order by rand() " +
" limit 1 ")
Medico escolherMedicoAleatorioLivre(Especialidade especialidade, LocalDateTime data);
@Query("select m.ativo" +
"from Medicos m" +
"where m.id = :id")
Boolean findAtivoById(Long id);
}