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类型数组。
SpringBoot启动异常解析
本文介绍了一种常见的SpringBoot启动时出现的依赖注入错误,并详细解释了解决该问题的方法。通过调整@SpringBootApplication注解中的exclude配置,成功解决了找不到PersonDao Bean的问题。

被折叠的 条评论
为什么被折叠?



