spring boot整合jpa启动报错

本文介绍了一种常见的SpringBoot启动时出现的依赖注入错误,并详细解释了解决该问题的方法。通过调整@SpringBootApplication注解中的exclude配置,成功解决了找不到PersonDao Bean的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spring boot启动报错:

 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personController': Unsatisfied dependency expressed through field 'personDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.demo.dao.PersonDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

报错代码:

启动类:


controller层:


dao层:


解决:去掉exclude = DataSourceAutoConfiguration.class。

说明:@SpringBootApplication中的属性:

  • Class<?>[] exclude() default {}:
    根据class来排除,排除特定的类加入spring容器,传入参数value类型是class类型。
  • String[] excludeName() default {}:
    根据class name来排除,排除特定的类加入spring容器,传入参数value类型是class的全类名字符串数组。
  • String[] scanBasePackages() default {}:
    指定扫描包,参数是包名的字符串数组。
  • Class<?>[] scanBasePackageClasses() default {}:
    扫描特定的包,参数类似是Class类型数组。
当然每个人遇到的问题可能不同,这是困扰了我一个下午的一个异常,记录一下 ,唉。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值