weixin_43078650 2019-12-18 11:21 采纳率: 0%
浏览 757
已结题

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()
        );
    }
}

  • 写回答

1条回答

  • dabocaiqq 2019-12-18 11:21
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗