@SpringBootApplication和@ComponentScan不可同时使用

今天在启动类加上了@ComponentScan(value = "com.mgx")注解,想要扫描到mgx包下的内容,但是却爆红线了,让我移除掉。

Redundant declaration: @SpringBootApplication already applies given @ComponentScan 

 可能是注解有问题,可能是冲突,也可能是冗余,首先@SpringBootApplacation注解映入眼帘,点进去一看,原来@SpringBootApplacation注解中就包含了@ComponentScan。

将@SpringBootApplacation给注释掉之后,发现@ComponentScan不再爆红线。

总结: @SpringBootApplacation中包含了@ComponentScan注解,有 @SpringBootApplacation时再加入@ComponentScan就造成了注解的冗余,因此两者不能同时存在。

猜你喜欢

转载自blog.csdn.net/qq_42405688/article/details/127085136