美文网首页
springboot-stack over flow

springboot-stack over flow

作者: Statham_Jessie | 来源:发表于2020-11-30 23:17 被阅读0次

Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

问题分析:并没有使用@ComponentScanning注解,这里为什么会蹦出个这样的注解呢?

SpringBoot在编写启动类(Main方法所在的类)的时候如果不使用@ComponentScan指明对象扫描范围,默认指扫描当前启动类所在的包里的对象。

(注意:我在编写Main方法的时候并没有加@ComponentScan注解,因而,他会扫描Application所在的包里的对象)

如果当前启动类没有包,则在启动时会报错:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package错误。

(注意:写在java文件夹下的Application类,是不从属于任何一个包的,因而启动类没有包)

解决办法:

方法一、将Application建在其他的包下面

方法二、在Application类上面加@ComponentScan注解,指定要扫描的包

相关文章

网友评论

      本文标题:springboot-stack over flow

      本文链接:https://www.haomeiwen.com/subject/grcjwktx.html