Feign 注入失敗之坑


今天碰到一個很坑的問題,feign 注入失敗。

錯誤信息:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
12-18 15:29:57.654 ERROR [o.s.b.diagnostics.LoggingFailureAnalysisReporter] -

***************************
APPLICATION FAILED TO START
***************************

Description:

Field messageFeign in com.pance.scheduler.mdm.dataCenterTask.DataCenter required a bean of type 'com.pance.common.feign.MessageFeign' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.pance.common.feign.MessageFeign' in your configuration.

 

很簡單的一個報錯信息,

直接看Application ,發現以及包含注解 @EnableFeignClients,以及 @ComponentScan("com.pance"),並且feign 也包含在 com.pance目錄下。

查了良久,

終於在最崩潰的時候,發現了一個細節的坑,feign 時在另外的common 包中引入的,雖然@ComponentScan("com.pance") 指定了掃描路徑包含了feign 的路徑,但是feign如果不是在相同的module 下,就必須加上 自己的掃描范圍,例如

@EnableFeignClients(basePackages = "com.pance")

加上之后,問題解決。

 

@EnableFeignClients(basePackages = "com.pance")
@ComponentScan("com.pance")
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class SchedulerApplication {
    public static void main(String[] args) {
        /*only start one application*/
        SpringApplication.run(SchedulerApplication.class, args);
    }
}

  

=====================================

發現網上說都是要配置@EnableFeignClients,以及引入jar 包,但是這個basePackage 這個值很少有說明。就寫一下自己踩坑的慘痛經歷。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM