我在春季启动时构建了一个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
}
}
DreamHospitalApplication
存在于com.DreamHospital.DreamHospital
软件包中,而MedecinDao
中存在dreamHospital.Dao.MedecinRepository
。 似乎您是一个初学者,应该将所有存储库包都保留在主应用程序包中。还有其他可能的方法,例如在Main class上使用批注EnableJpaRepositories
,您可以随时学习。