spring boot :No qualifying bean of type ‘XXX.X‘ available
程序员文章站
2022-07-12 11:37:26
...
背景:
想用容器接收spring boot 启动加载的bean
1、新建了个spring boot项目,
2、搞了个PandaService类,写个hello 方法,简单输出
3、在启动类main方法中,用容器ApplicationContext
去接收启动加载的类
4、通过反射获取PandaService
对象,调hello方法
5、代码结构如图,so easy
启动报错如下:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.service.impl.PandaServiceImpl' 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:1179)
at com.panda.PandaApplication.main(PandaApplication.java:18)
解决:
报错提示没有可用的bean来定义,也就是说spring没有扫到PandaServiceImpl
在启动类设置的IOC容器中设置包扫描路径,**@ComponentScan("com.service")
**即可
结果:
上一篇: xilinx FPGA约束文件
下一篇: Jumpserver-堡垒机