spring boot测试报org.springframework.beans.factory.NoSuchBeanDefinitionException错误

环境:eclipse 2018 12版本
原因是其他的类与主程序类不在同一个包中,springboot扫描不到
解决办法:在主程序上加上注解@ComponentScan(basePackages="xxx.xxx") 其中xxx.xxx为包名
位于不同的包
如果把ComponentScan注释掉,就会报错
在这里插入图片描述
在这里插入图片描述
转载地址

猜你喜欢

转载自blog.csdn.net/weixin_43763175/article/details/90318867