一、問題
Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
二、問題描述
在自定義spring-boot的啓動監聽器時報錯,意思是說有多個內容加載監聽器,導致項目無法啓動。
三、問題解決
原錯誤代碼:
/**
* 項目啓動監聽器
*/
@Component
public class StartListener extends ContextLoaderListener implements ApplicationRunner {
@Override
public void contextInitialized(ServletContextEvent event) {
super.contextInitialized(event);
}
@Override
public void run(ApplicationArguments args) {
}
}
原因就是在重載contextInitialized()方法時,調用了父類的初始化方法;去掉 super.contextInitialized(event);即可。