Spring boot web应用程序Spring引导中没有类型的限定bean

Spring boot web应用程序Spring引导中没有类型的限定bean,spring-boot,spring-data-jpa,Spring Boot,Spring Data Jpa,我正在SpringBoot中构建一个web应用程序,我面临这个错误,它找不到bean“MedecinDao”,尽管我在MedecinDao中添加了@component 对于medecinDao来说,这是一个接口 有人能帮我吗 Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'dreamHospital

我正在SpringBoot中构建一个web应用程序,我面临这个错误,它找不到bean“MedecinDao”,尽管我在MedecinDao中添加了@component 对于medecinDao来说,这是一个接口 有人能帮我吗

    Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'dreamHospital.Dao.MedecinRepository' available
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1126)
    at com.DreamHospital.DreamHospital.DreamHospitalApplication.main(DreamHospitalApplication.java:23

你需要了解jpa和springboot。Springboot自动在JPA存储库上创建bean,这些存储库位于主应用程序的相同或嵌套包中。 您的主要应用程序即DreamHospital应用程序存在于com.DreamHospital.DreamHospital包中 MedecinDao目前在dreamHospital.Dao.MedecinRepository


看起来你是一个初学者,你应该把所有的存储库包都放在主应用程序包中。还有其他可能的方法,比如在Main类上使用注释启用JParepositories,您可以随时间学习。

请将代码添加为代码,而不是图像。阅读常见问题解答并阅读本文
@SpringBootApplication
public class DreamHospitalApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context= SpringApplication.run(DreamHospitalApplication.class, args);


        MedecinDao MD  = context.getBean(MedecinDao.class);
        medecin M1 = new medecin("Azzedine RIHANE","Dermatologiste");
        medecin M2 = new medecin("Riadh Bouftira","Médecin de famille");
        medecin M3 = new medecin("Khaled Machraoui","Médecin de famille");
        medecin M4 = new medecin("Mohamed Moalla","Rhumatologue");
        medecin M5 = new medecin("Abderrazek Mnif","Urologue");
        medecin M6 = new medecin("ghezel slim","Dermatologiste");
        medecin M7 = new medecin("Mounir Makni","Gynécologue");
@Component
public interface MedecinDao extends JpaRepository<medecin, UUID>{

    List<medecin> findAll();
    List<medecin> findBySpecialite(String specialite);

    List<medecin> findByPatients(patient patient);

    @Override
    default Optional<medecin> findById(UUID id) {
        // TODO Auto-generated method stub
        return null;
    }

    @Query("select patients from medecin m where m.idM like : x")
    List<patient> findPatients(@Param("x")UUID idM);

    @Override
    default void deleteById(UUID id) {
        // TODO Auto-generated method stub  
    }
}