重写sentinel 的feign builder 后服务启动时 feignSentinelBuilder 与 seata 的 feignSentinelBuilder 冲突
微服务项目同时集成了 sentinel 版本 2021.1 seata 版本1.4.2 spring boot 版本 2.4.3 spring cloud版本 2020.0.1 为了避免写fallback和fallbackFacotry类,重写SentinelFeign.builder()类
@Configuration(proxyBeanMethods = false) @AutoConfigureBefore(SentinelFeignAutoConfiguration.class) public class XxxSentinelAutoConfiguration { @Bean @Scope("prototype") @ConditionalOnMissingBean public Feign.Builder feignSentinelBuilder() { return XxxSentinelFeign.builder(); } }
这样导致服务无法启动,错误如下:
APPLICATION FAILED TO START
Description:
The bean 'feignSentinelBuilder', defined in class path resource [com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [cn/xxx/xxx/common/sentinel/XxxSentinelAutoConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
不知道哪位大佬有没有遇到过类似的问题,尝试过一下解决方案:
- 将 feignSentinelBuilder 改个名字,这样会导致FeignClient注解的Bean不能加载
- 将 feign.sentinel.enable 设置为false,这样直接导致 seata 全局事务失效
你这个问题解决了吗?我也碰到了类似的问题,正在寻求解决方案
同问
要不试试@AutoConfigureBefore({FeignAutoConfiguration.class, SentinelFeignAutoConfiguration.class})?
This issue has been open 30 days with no activity. This will be closed in 7 days.
This issue has been automatically marked as stale because it hasn't had any recent activity.If you think this should still be open, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. Thank you for your interest and contribution to the Sping Cloud Alibaba Community.