Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package

來源:互聯網
上載者:User

標籤:line   pac   warning   分享   問題   包括   指定   掃描   main   

1、在搭建SpringBoot架構時碰到的問題。

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

警告:你的應用上下文可能沒有啟動,因為你將註解添加到了預設的package上面了。下面的堆棧資訊中也有一句話包括了這個意思。

......This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)。

(啟動的時候還有其他的錯誤,這裡只摘錄跟這個相關的錯誤。)

 

2、我的項目結構是這樣的(我將Application的檔案建在了java檔案夾下面)

 

3、原因解析

我並沒有使用@ComponentScanning註解,這裡為什麼會蹦出個這樣的註解呢?

SpringBoot在編寫啟動類(Main方法所在的類)的時候如果不使用@ComponentScan指明對象掃描範圍,預設指掃描當前啟動類所在的包裡的對象。

(注意:我在編寫Main方法的時候並沒有加@ComponentScan註解,因而,他會掃描Application所在的包裡的對象)
如果當前啟動類沒有包,則在啟動時會報錯:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package錯誤。

(注意:寫在java檔案夾下的Application類,是不從屬於任何一個包的,因而啟動類沒有包)

 

4、解決辦法

方法一、將Application建在其他的包下面

方法二、在Application類上面加@ComponentScan註解,指定要掃描的包

 

參考文檔

http://blog.csdn.net/u012834750/article/details/65942092

 

Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.