關於報錯Consider defining a bean of type 的解決

運行SpringBoot的時候報如下錯Consider defining a bean of type 'com.google.code.kaptcha.Producer' in your configuration.

報錯原因爲配置中找不到一個指定自動注入類型的bean。

那麼我們要從collecter層開始查找,點擊service層,看service實現類是否加上@Service或者@Component,檢查service實現類是否有implements service。如果這些都沒有問題:

我們來看@SpringBootApplication,點過去。可以看到有個@ComponentScan,ComponentScan做的事情就是告訴Spring從哪裏找到bean

那可以直接在@SpringBootApplication加上

@SpringBootApplication
@ComponentScan(basePackages ={"com.google.code" })
public class OfficialSystemApplication {

    public static void main(String[] args) {
        SpringApplication.run(OfficialSystemApplication.class,args);
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章