1. 程式人生 > >Springboot 中報錯 Your ApplicationContext is unlikely to start due to a @ComponentScan

Springboot 中報錯 Your ApplicationContext is unlikely to start due to a @ComponentScan

用springboot 寫scala程式碼是最近做的一個專案,但是我啟動的時候拋了一個錯誤,具體就是Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package

大概意思就是ApplicationContext 不能從一個元件的預設包啟動

SpringBoot在寫啟動類的時候如果不使用@ComponentScan指明物件掃描範圍,預設指掃描當前啟動類所在的包裡的物件,如果當前啟動類沒有包,則在啟動時會報錯Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package

我們需要新建一個包,然後把啟動類放到新的包下面就可以了

比如我新建了一個controller包,然後把程式碼放到controller包下面,問題解決!

或者使用@ComponentScan註解

@SpringBootApplication
@ComponentScan(basePackageClasses=MytestApplication.class)
def  MytestApplication {}
}