idea下Gradle创建Springboot项目时报如下错误:
This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
是因为包名没有找到
SpringBoot在编写启动类、的时候如果不使用@ComponentScan指明对象扫描范围,默认指扫描当前启动类所在的包里的对象,java目录的Application类,是不从属于任何一个包的,因而启动类没有包
解决办法:
1. 根目录下的启动类中加入@ComponentScan(后面的包类名为不能是/main/java根目录下的类),这种方法每一个包都要提前写在注解中
SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan @ComponentScan(basePackageClasses = MonitorConfigController.class)2. 将启动类放在某个包下,不要放在java根目录下