Redundant declaration: @SpringBootApplication already applies given @ComponentScan


一.错误

Redundant declaration: @SpringBootApplication already applies given @ComponentScan(冗余声明:@SpringBootApplication已应用于给定的@ComponentScan)

二.场景

这是我在给微服务配置feign负载平衡的时候,我要在(feign模块)配置去扫描(api模块)下的包,然后出现下面的bug @ComponentScan的注解报红

![在这里插入图片描述](https://img-blog.csdnimg.cn/167c6b393b824a33b73c615ab62f5941.png


三.原因

已知@ComponentScan会默认扫描当前包

我要扫描的另一个模块包下的service的包 (api模块)
在这里插入图片描述

我当前模块的包 (feign模块)

在这里插入图片描述

因为我的配置是@ComponentScan(“com.xin”),然后当前模块和我想要扫描的包都有com.xin,再加上@ComponentScan默认扫描当前包,所以这就会报你的注解是冗余的


四.解决方法

1.把你要扫描的包写的更详细一点

在这里插入图片描述


2.把你要导入的包改一个名字

在这里插入图片描述
我直接把api模块的包名改了,这样就不和feign模块的包名冲突了,解决。

不过我又试了试,现在微服务集成feign不需要@ComponentScan也是可以的,你要去掉@ComponentScan是可以正常访问的,那就不需要,如果不可以正常访问,那就只能按上面的配置

猜你喜欢

转载自blog.csdn.net/twotwo22222/article/details/125873555