標籤: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