1. 程式人生 > >springboot 專案 注意事項

springboot 專案 注意事項

SpringBoot出現下列錯誤。

Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package
Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception


或者

Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package
Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception


或者
ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot

[email protected]4b9e255: startup date [Wed Jul 26 13:37:27 CST 2017]; root of context hierarchy

 


主要是由於application.java檔案沒有放在main/java資料夾的原因,因為application.Java 檔案不能直接放在main/java資料夾下,必須要建一個包把他放進去
SpringBoot在寫啟動類的時候如果不使用@ComponentScan指明物件掃描範圍,預設指掃描當前啟動類所在的包裡的物件,如果當前啟動類沒有包,則在啟動時會報錯:
Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package錯誤。


@SpringBootApplication
@ComponentScan(basePackageClasses=MytestApplication.class)
public class MytestApplication {


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

 

@ComponentScan(basePackageClasses=要掃描類.class所在位置的包)-意思是要掃描哪個類所在的包
---------------------
作者:King-Long
來源:CSDN
原文:https://blog.csdn.net/u011095110/article/details/76144416