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类型数组。