spring boot 2外部tomcat启动错误:check whether you have multiple ContextLoader* definitions in your web.xml!

spring boot 2外部tomcat启动错误

java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!

pom:

 <!-- Spring Boot Dubbo 依赖 -->
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!-- <scope>compile</scope>-->
            <scope>provided</scope><!-- 必须要加,不然报错 -->
        </dependency>

<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-velocity</artifactId>-->
<!--            <version>1.2.2.RELEASE</version>-->
<!--        </dependency>-->

<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-legacy</artifactId>-->
<!--            <version>1.1.0.RELEASE</version>-->
<!--        </dependency>-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>0.2.0</version>
        </dependency>

web.xml检查过没有ContextLoaderListener,ContextLoaderListener和RequestContextListener写在代码中

@Configuration
public class ListenerConfig {

    /**
     * 配置 RequestContextListener
     * @return
     */
    @Bean
    public ServletListenerRegistrationBean<RequestContextListener> listenerRegistration1() {
        return new ServletListenerRegistrationBean<>(
            new RequestContextListener());
    }

    /**
     * 配置 ContextLoaderListener
     * @return
     */
    @Bean
    public  ServletListenerRegistrationBean<ContextLoaderListener> listenerRegistration2(){
        return new ServletListenerRegistrationBean<>(
            new ContextLoaderListener()
        );
    }
}

https://blog.csdn.net/baicp3/article/details/90674932