Eu revi todo o código mas não consegui detectar o erro Error creating bean with name 'medicoController': Unsatisfied dependency
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'medicoController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'medicoRepository' defined in med.voll.api.medico.MedicoRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Not a managed type: class med.voll.api.medico.Medico
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:743) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:723) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:127) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6]
Caused by: 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: Not a managed type: class med.voll.api.medico.Medico
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1754) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.0.0-M6.jar:6.0.0-M6]
... 25 common frames omitted
Caused by: java.lang.IllegalArgumentException: Not a managed type: class med.voll.api.medico.Medico
at org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.managedType(JpaMetamodelImpl.java:181) ~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:496) ~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.managedType(MappingMetamodelImpl.java:99) ~[hibernate-core-6.1.3.Final.jar:6.1.3.Final]
Classe MedicoController
@RestController
@RequestMapping("medicos")
public class MedicoController {
@Autowired
private MedicoRepository repository;
@PostMapping
@Transactional
public void cadastrar(@RequestBody CadastroMedico dados) {
repository.save(new Medico(dados));
}
}
Medico Repository
@Repository
public interface MedicoRepository extends JpaRepository<Medico, Long> {
}
Classe Medico
@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 telefone;
private String crm;
@Enumerated(EnumType.STRING)
private Especialidade especialidade;
@Embedded
private Endereco endereco;
public Medico(CadastroMedico dados) {
this.nome = dados.nome();
this.email = dados.email();
this.crm = dados.crm();
this.especialidade = dados.especialidade();
this.endereco = new Endereco(dados.endereco());
}