Cannot initialize context becaus

2020-02-20  本文已影响0人  WebProgress

一、问题

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);即可。

上一篇下一篇

猜你喜欢

热点阅读