最近接到任務,重構公司的支付中心。目前公司有兩套基礎架構(在框架上在做封裝),一套比較老,一套比較新。
既然是重構自然而然選擇了新的一套。
雖然是重構,但是其他的訂單業務還是老的一套,多多少少還是需要和他們對接。
在引用其他老項目的FeignClient。idea 一直提示Could not autowire. No beans of 'xxxx' type found。
因為只是提示我也就沒理會,啟動項目的時候報錯了:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class xxx; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'feginClientConfig' for bean class xxxx conflicts with existing, non-compatible bean definition of same name and class xxxx。
項目啟動不了,就沒辦法往下走,於是就慢慢排查。
最后發現是因為老項目的FeignClient是在org.springframework.cloud.netflix.feign.FeignClient 下
而我用的新的FeignClient卻是在org.springframework.cloud.openfeign.FeignClient 下。
原來Spring Cloud對Feign的支持由org.springframework.cloud:spring-cloud-netflix-core移到org.springframework.cloud:spring-cloud-openfeign-core下了,所以導致掃描包一直掃描不到,所以idea 提示Could not autowire. No beans of 'xxxx' type found。
解決辦法:
可以不依賴其他項目的Client。在自己項目把其他項目Client重新寫一個,然后@FeignClient注解引org.springframework.cloud.openfeign.FeignClient包下的,接完美解決了。