Quando criei o MedicoRepository começou a dar o seguinte erro na inicialização:
2022-12-27 14:29:45.538 WARN 2535 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'medicoController': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'medicoRepository' defined in med.voll.api.medico.MedicoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class med.voll.api.medico.Medico
package med.voll.api.medico;
import org.springframework.data.jpa.repository.JpaRepository;
public interface MedicoRepository extends JpaRepository<Medico, Long>{
}
@RestController @RequestMapping("medicos") public class MedicoController {
@Autowired
private MedicoRepository repository;
@PostMapping
@Transactional
public void cadastrar(@RequestBody DadosCadastroMedico dados) {
repository.save(new Medico(dados));
}
}
@Table(name = "medicos") @Entity(name = "Medico") @Getter @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(of = "id") public class Medico {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
private String email;
private String crm;
@Enumerated(EnumType.STRING)
private Especialidade especialidade;
@Embedded
private Endereco endereco;
public Medico(DadosCadastroMedico dados) {
this.nome = dados.getNome();
this.email = dados.getEmail();
this.crm = dados.getCrm();
this.especialidade = dados.getEspecialidade();
this.endereco = new Endereco(dados.getEndereco());
}
}