maven 普通模塊A依賴 feign公共接口模塊B的,
A的App啓動類在com.test.pro.gms包下
B的接口在 com.test.api.service 包下
程序中 A 的service通過 @Autowired 方式注入B的ProductFeignService接口。 在調用是,debug到這個接口對象爲空
在官網找到的方法爲
在App.java中加入
@ComponentScan({"com.test.pro.gms","com.test.api.service"})
feign接口對象依然爲空。但是service包下的其他class bean對象能夠注入成功,並且能夠調用方法。
在網上搜索後發現,改變A的啓動類位置可以解決
A 的啓動類App.java 移動到com.test下能夠正常調用,com.test包屬於模塊A和模塊B的共同基礎包
這個是正解,但是interface無法通過ComponentScan掃描裝配的問題等着後面繼續研究。
@ComponentScan 能夠掃描到jar包中的bean註解, 但是對於沒有實現類的接口,(例如api模塊B中直接使用接口
@FeignClient("test-server")
public interface ProService {
無法在A模塊找到