Web应用程序Spring Boot中的'没有合格的类型的豆'

问题描述 投票:0回答:1

我在春季启动时构建了一个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
@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  
    }
}

spring-boot spring-data-jpa
1个回答
0
投票
您需要阅读有关jpa和springboot的信息。 Springboot自动在JPA存储库上创建Bean,这些存储在主应用程序的相同或嵌套软件包中。您的主应用程序即DreamHospitalApplication存在于com.DreamHospital.DreamHospital软件包中,而MedecinDao中存在dreamHospital.Dao.MedecinRepository

似乎您是一个初学者,应该将所有存储库包都保留在主应用程序包中。还有其他可能的方法,例如在Main class上使用批注EnableJpaRepositories,您可以随时学习。

© www.soinside.com 2019 - 2024. All rights reserved.