问题
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.tian.sky.javaBean.entity.UserBaseEntity’ available
分析:
- 有没有同名的类
- 有没有扫描到类
1、如果是用的spring.xml文件的形式需要检查一下是否有同名的。
2、这里是用的JavaConfig,是没有重名的类的,所以可以想想是不是没有扫描到类
检查:
- 检查点一:javaConfig类是否写了@Configuration 、@ComponentScan(basePackages = “com.tian.sky.javaBean”)
- @Configuration:这个可以代替spring.xml文件使用AnnotationConfigApplicationContext进行初始化ioc容器
- @ComponentScan是扫描用的,basePackages 指定要扫描的包。
- 检查点二:检查要从容器中取出来的bean对象是否写了@Component注解,或者其他三大注解(@Controller、@Service、@Repository)
总结
最后检查我自己的是因为没有写@Component注解,导致就算basePackages 指定的路径下存在我这个javaBean也扫描不到。